diff --git a/README.md b/README.md index 756dd11..0b1568c 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,11 @@ A dummy application for a bank; should provide various functions of a retail ban ### Additional Features + * A customer can transfer between their accounts + * Done with accountTransfer function in the customer.py Customer class. Users must own both the from account and to account. Tested with the testAccountTransfer function in bank_tests.py * Change **Maxi-Savings accounts** to have an interest rate of 5% assuming no withdrawals in the past 10 days otherwise 0.1% -* Interest rates should accrue daily (incl. weekends), rates above are per-annum \ No newline at end of file + + * Done with the interestEarned function in account.py that tests if the last withdraw(amount <0) transaction occured less than 10 days ago for maxi savings. Tested with the test_maxi_savings_account and test_maxi_savings_withdraw functions within the bank_tests.py +* Interest rates should accrue daily (incl. weekends), rates above are per-annum + * Done with the interestEarned function in account.py that will divide the annual interest rate by 365.25. This assuming that the interestEarned function will be executed once daily. diff --git a/abcbank/account.py b/abcbank/account.py index e010009..3efc760 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -1,4 +1,5 @@ from abcbank.transaction import Transaction +from datetime import datetime, timedelta CHECKING = 0 SAVINGS = 1 @@ -23,21 +24,22 @@ def withdraw(self, amount): self.transactions.append(Transaction(-amount)) def interestEarned(self): + ##change to include rule for maxi savings where interest is 5% if no withdraw in past 10 days, else 0.1% amount = self.sumTransactions() if self.accountType == SAVINGS: if (amount <= 1000): - return amount * 0.001 + return amount * (0.001/365.25) else: - return 1 + (amount - 1000) * 0.002 + return 1 + (amount - 1000) * 0.002/365.25 if self.accountType == MAXI_SAVINGS: - if (amount <= 1000): - return amount * 0.02 - elif (amount <= 2000): - return 20 + (amount - 1000) * 0.05 - else: - return 70 + (amount - 2000) * 0.1 + todaysDate=datetime.now() + withdrawTransactions=[t.transactionDate for t in self.transactions if t.amount<0] ##get list withdraw transactions as amount < zero. + if len(withdrawTransactions)>0: + if (withdrawTransactions[-1]>(todaysDate-timedelta(days=10))): + return amount * 0.001/365.25 + return amount * 0.05/365.25 else: - return amount * 0.001 + return amount * 0.001/365.25 def sumTransactions(self, checkAllTransactions=True): - return sum([t.amount for t in self.transactions]) \ No newline at end of file + return sum([t.amount for t in self.transactions]) diff --git a/abcbank/customer.py b/abcbank/customer.py index 7cfd62a..ee68961 100644 --- a/abcbank/customer.py +++ b/abcbank/customer.py @@ -16,6 +16,16 @@ def numAccs(self): def totalInterestEarned(self): return sum([a.interestEarned() for a in self.accounts]) + def accountTransfer(self, fromAccount, toAccount, amount): + ##create account transfer system where users can withdraw from one account and deposit into another account within the banking system + if fromAccount not in self.accounts: + return 0.0 #only perform transfer if user owns both accounts + if toAccount not in self.accounts: + return 0.0 + fromAccount.withdraw(amount) + toAccount.deposit(amount) + return amount + # This method gets a statement def getStatement(self): # JIRA-123 Change by Joe Bloggs 29/7/1988 start diff --git a/tests/bank_tests.py b/tests/bank_tests.py index 6de98db..ed3aec2 100644 --- a/tests/bank_tests.py +++ b/tests/bank_tests.py @@ -19,7 +19,7 @@ def test_checking_account(): bill = Customer("Bill").openAccount(checkingAccount) bank.addCustomer(bill) checkingAccount.deposit(100.0) - assert_equals(bank.totalInterestPaid(), 0.1) + assert_equals(bank.totalInterestPaid(), 0.1/365.25) def test_savings_account(): @@ -27,7 +27,7 @@ def test_savings_account(): checkingAccount = Account(SAVINGS) bank.addCustomer(Customer("Bill").openAccount(checkingAccount)) checkingAccount.deposit(1500.0) - assert_equals(bank.totalInterestPaid(), 2.0) + assert_equals(bank.totalInterestPaid(), 1 + (1500 - 1000) * 0.002/365.25) def test_maxi_savings_account(): @@ -35,4 +35,29 @@ def test_maxi_savings_account(): checkingAccount = Account(MAXI_SAVINGS) bank.addCustomer(Customer("Bill").openAccount(checkingAccount)) checkingAccount.deposit(3000.0) - assert_equals(bank.totalInterestPaid(), 170.0) \ No newline at end of file + assert_equals(bank.totalInterestPaid(), 150.0/365.25) + + +def test_maxi_savings_withdraw(): + bank = Bank() + checkingAccount = Account(MAXI_SAVINGS) + bank.addCustomer(Customer("Bill").openAccount(checkingAccount)) + checkingAccount.deposit(3000.0) + checkingAccount.withdraw(10) + assert_equals(bank.totalInterestPaid(), (3000.0-10.0)*0.001/365.25) + + + +def testAccountTransfer(): + bank = Bank() + checkingAccount = Account(CHECKING) + bill = Customer("Bill").openAccount(checkingAccount) + bank.addCustomer(bill) + checkingAccount.deposit(100.0) + savingAccount = Account(SAVINGS) + bill.openAccount(savingAccount ) + savingAccount.deposit(10000) + bill.accountTransfer(savingAccount, checkingAccount, 500) + assert_equals(checkingAccount.sumTransactions(), 600.0) + +