Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def transfer(self, amount: float, receiver_account: 'Account'):
- """Transfer money from one account to another."""
- if amount <= 0:
- raise TransactionError("Amount is lower or equal to 0")
- elif self._balance < amount:
- raise TransactionError("Amount is lower or equal to 0")
- elif receiver_account.bank != self.bank and self._balance < amount + 5:
- raise TransactionError("Amount is lower than 5 or not enough money")
- elif self == receiver_account:
- raise TransactionError("The bank is the same")
- else:
- transaction = Transaction(-amount, datetime.date.today(), self, receiver_account, False)
- self.transactions.append(transaction)
- self.bank.transactions.append(transaction)
- if receiver_account.bank != self.bank:
- self.withdraw(5, False)
- receiver_account.deposit(amount, False)
- receiver_account.bank.transactions.append(transaction)
- receiver_account.transactions.append(transaction)
- self.withdraw(amount, False)
- receiver_account._balance += amount
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement