def apply_transaction(self, transaction: Transaction): """Overrides super as the behaviors for applying certain transactions differs. For reg D accounts, infinite deposits are allowed, but only a specified number of withdrawals. Args: transaction (Transaction): The transaction to apply. Raises: OverdraftLimitExceeded: Raised when the limit is exceeded. RegulationDLimitMet: Raised when the limit is is met. UnrecognizedTransactionType: Rasied when teh transaction type is not allowed. """ if transaction.get_type() == TranType.DEPOSIT: self._balance += transaction.get_amt self.trans_hist.append(transaction) elif transaction.get_type() == TranType.WITHDRAWAL: if self.withdrawal_count < self.__REG_D_MAX: if self._balance - transaction.get_amt() < 0.0: if (abs(self._balance - transaction.get_amt()) <= self.overdraft_limit and abs(self._balance - transaction.get_amt()) <= self.overdraft_amount): self._balance -= transaction.get_amt() self.trans_hist.append(transaction) else: raise OverdraftLimitExceeded else: self._balance -= transaction.get_amt() self.trans_hist.append(transaction) else: raise RegulationDLimitMet else: raise UnrecognizedTransactionType
def apply_transaction(self, transaction: Transaction): """Public function to apply a transaction. Determines type of transaction byt it's type and calls the private functions __credit or __debit to apply it to the balance. Args: transaction (Transaction): This si the transaction to apply to the balance. Raises: UnrecognizedTransactionType: Raised if the transaction passed has a type thaat is not allowed for application to an account balance. """ if transaction.get_type() == TranType.DEPOSIT: self.__credit(transaction.get_amt()) self.trans_hist.append(transaction) elif transaction.get_type() == TranType.WITHDRAWAL: self.__debit(transaction.get_amt()) self.trans_hist.append(transaction) else: raise UnrecognizedTransactionType
def apply_transaction(self, transaction: Transaction): """Overrides super. In draft accounts there is additional behavior to check balance and apply overdraft in the case of insufficient funds (NSF). Args: transaction (Transaction): The transaction to be applied. Raises: OverdraftLimitExceeded: Raised when OD limit is exceeded by the transaction. UnrecognizedTransactionType: Same behavior as super. """ if transaction.get_type() == TranType.DEPOSIT: self.balance += transaction.get_amt() self.trans_hist.append(transaction) elif transaction.get_type() == TranType.WITHDRAWAL: if self.balance - transaction.get_amt() < 0.0: if (abs(self.balance - transaction.get_amt()) <= self.overdraft_limit and abs(self.balance - transaction.get_amt()) <= self.overdraft_amount): self.balance -= transaction.get_amt() self.trans_hist.append(transaction) else: raise OverdraftLimitExceeded else: self.balance -= transaction.get_amt() self.trans_hist.append(transaction) elif transaction.get_type() == TranType.FEE: self.apply_fee(self.draft_income_gl) else: raise UnrecognizedTransactionType