diff --git a/abcbank/account.py b/abcbank/account.py index e010009..1841aab 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -1,4 +1,6 @@ from abcbank.transaction import Transaction +from abcbank.customer import Customer +from date_provider import DateProvider CHECKING = 0 SAVINGS = 1 @@ -9,6 +11,7 @@ class Account: def __init__(self, accountType): self.accountType = accountType self.transactions = [] + self.logintimes= [] def deposit(self, amount): if (amount <= 0): @@ -22,22 +25,42 @@ def withdraw(self, amount): else: self.transactions.append(Transaction(-amount)) + def transfer(self,initial_account,final_account,amount): + if (amount <= 0): + raise ValueError("amount must be greater than zero") + elif Customer.numAccs()<=1: + raise ValueError("You must have at least 2 accounts") + else: + self.accountType=initial_account + self.withdraw(amount) + self.accountType=final_account + self.deposit(amount) + def interestEarned(self): amount = self.sumTransactions() - if self.accountType == SAVINGS: - if (amount <= 1000): - return amount * 0.001 - else: - return 1 + (amount - 1000) * 0.002 - 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 + #This is a false date for testing. A real account would already have recorded the previous transactions + t=date('2015','11','09') + self.logintimes.append(t) + + currentTime=DateProvider() + if self.logintimes is empty: + return amount*0 else: - return amount * 0.001 + instance=len(self.logintimes) + lasLogin=self.logintimes[instance] + diff=currentTime-lasLogin + if self.accountType == SAVINGS: + if (amount <= 1000): + return amount * 0.001*diff.days + else: + return 1 + (amount - 1000) * 0.002*diff.days + if self.accountType == MAXI_SAVINGS: + if diff.day >=10: + return amount * 0.05*diff.days + else: + return amount * 0.001*diff.days + else: + return amount * 0.001*diff.days 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/tests/customer_tests.py b/tests/customer_tests.py index 0211a4f..264cda8 100644 --- a/tests/customer_tests.py +++ b/tests/customer_tests.py @@ -1,6 +1,6 @@ from nose.tools import assert_equals, nottest -from account import Account, CHECKING, SAVINGS +from account import Account, CHECKING, SAVINGS, MAXI_SAVINGS from customer import Customer @@ -33,4 +33,4 @@ def test_twoAccounts(): def test_threeAccounts(): oscar = Customer("Oscar").openAccount(Account(SAVINGS)) oscar.openAccount(Account(CHECKING)) - assert_equals(oscar.numAccs(), 3) \ No newline at end of file + assert_equals(oscar.numAccs(), 3)