Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

* 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.
22 changes: 12 additions & 10 deletions abcbank/account.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abcbank.transaction import Transaction
from datetime import datetime, timedelta

CHECKING = 0
SAVINGS = 1
Expand All @@ -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])
return sum([t.amount for t in self.transactions])
10 changes: 10 additions & 0 deletions abcbank/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 28 additions & 3 deletions tests/bank_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,45 @@ 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():
bank = Bank()
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():
bank = Bank()
checkingAccount = Account(MAXI_SAVINGS)
bank.addCustomer(Customer("Bill").openAccount(checkingAccount))
checkingAccount.deposit(3000.0)
assert_equals(bank.totalInterestPaid(), 170.0)
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)