Advertisement
UniQuet0p1

Untitled

Nov 16th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. def transfer(self, amount: float, receiver_account: 'Account'):
  2. """Transfer money from one account to another."""
  3. if amount <= 0:
  4. raise TransactionError("Amount is lower or equal to 0")
  5. elif self._balance < amount:
  6. raise TransactionError("Amount is lower or equal to 0")
  7. elif receiver_account.bank != self.bank and self._balance < amount + 5:
  8. raise TransactionError("Amount is lower than 5 or not enough money")
  9. elif self == receiver_account:
  10. raise TransactionError("The bank is the same")
  11. else:
  12. transaction = Transaction(-amount, datetime.date.today(), self, receiver_account, False)
  13. self.transactions.append(transaction)
  14. self.bank.transactions.append(transaction)
  15. if receiver_account.bank != self.bank:
  16. self.withdraw(5, False)
  17. receiver_account.deposit(amount, False)
  18. receiver_account.bank.transactions.append(transaction)
  19. receiver_account.transactions.append(transaction)
  20. self.withdraw(amount, False)
  21. receiver_account._balance += amount
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement