code refactor

This commit is contained in:
MaysWind
2024-10-30 01:05:04 +08:00
parent 92a78f6f12
commit 90ea462206
2 changed files with 10 additions and 8 deletions
+10
View File
@@ -599,6 +599,11 @@ func (s *TransactionService) ModifyTransaction(c core.Context, transaction *mode
return errs.ErrTransactionSourceAndDestinationAmountNotEqual
}
if (transaction.Type == models.TRANSACTION_DB_TYPE_TRANSFER_OUT || transaction.Type == models.TRANSACTION_DB_TYPE_TRANSFER_IN) &&
(transaction.Amount < 0 || transaction.RelatedAccountAmount < 0) {
return errs.ErrTransferTransactionAmountCannotBeLessThanZero
}
oldSourceAccount, oldDestinationAccount, err := s.getOldAccountModels(sess, transaction, oldTransaction, sourceAccount, destinationAccount)
if err != nil {
@@ -1566,6 +1571,11 @@ func (s *TransactionService) doCreateTransaction(sess *xorm.Session, transaction
return errs.ErrTransactionSourceAndDestinationAmountNotEqual
}
if (transaction.Type == models.TRANSACTION_DB_TYPE_TRANSFER_OUT || transaction.Type == models.TRANSACTION_DB_TYPE_TRANSFER_IN) &&
(transaction.Amount < 0 || transaction.RelatedAccountAmount < 0) {
return errs.ErrTransferTransactionAmountCannotBeLessThanZero
}
// Get and verify category
err = s.isCategoryValid(sess, transaction)