mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-17 00:12:11 +08:00
don't allow adding balance modification transaction when account already has other transaction
This commit is contained in:
@@ -200,8 +200,16 @@ func (s *TransactionService) CreateTransaction(transaction *models.Transaction)
|
||||
return errs.ErrTransactionCategoryTypeInvalid
|
||||
}
|
||||
|
||||
// Calculate balance modification transaction real amount
|
||||
// Verify balance modification transaction and calculate real amount
|
||||
if transaction.Type == models.TRANSACTION_TYPE_MODIFY_BALANCE {
|
||||
otherTransactionExists, err := sess.Where("uid=? AND deleted=? AND destination_account_id=?", transaction.Uid, false, destinationAccount.AccountId).Limit(1).Exist(&models.Transaction{})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if otherTransactionExists {
|
||||
return errs.ErrBalanceModificationTransactionCannotAddWhenNotEmpty
|
||||
}
|
||||
|
||||
transaction.DestinationAmount = transaction.SourceAmount - destinationAccount.Balance
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user