fix some fields in transfer-out transaction does not be modified when modifying transfer-in transaction

This commit is contained in:
MaysWind
2021-01-11 23:04:00 +08:00
parent d7efeea24b
commit 62b7499cd0
+22 -1
View File
@@ -593,7 +593,8 @@ func (s *TransactionService) ModifyTransaction(transaction *models.Transaction,
return errs.ErrTooMuchTransactionInOneSecond
}
updatedRows, err := sess.ID(relatedTransaction.TransactionId).Cols(updateCols...).Where("uid=? AND deleted=?", relatedTransaction.Uid, false).Update(relatedTransaction)
relatedUpdateCols := s.getRelatedUpdateColumns(updateCols)
updatedRows, err := sess.ID(relatedTransaction.TransactionId).Cols(relatedUpdateCols...).Where("uid=? AND deleted=?", relatedTransaction.Uid, false).Update(relatedTransaction)
if err != nil {
return err
@@ -1050,6 +1051,26 @@ func (s *TransactionService) getOldAccountModels(sess *xorm.Session, transaction
return oldSourceAccount, oldDestinationAccount, nil
}
func (s *TransactionService) getRelatedUpdateColumns(updateCols []string) []string {
relatedUpdateCols := make([]string, len(updateCols))
for i := 0; i < len(updateCols); i++ {
if updateCols[i] == "account_id" {
relatedUpdateCols[i] = "related_account_id"
} else if updateCols[i] == "related_account_id" {
relatedUpdateCols[i] = "account_id"
} else if updateCols[i] == "amount" {
relatedUpdateCols[i] = "related_account_amount"
} else if updateCols[i] == "related_account_amount" {
relatedUpdateCols[i] = "amount"
} else {
relatedUpdateCols[i] = updateCols[i]
}
}
return relatedUpdateCols
}
func (s *TransactionService) isCategoryValid(sess *xorm.Session, transaction *models.Transaction) error {
if transaction.Type == models.TRANSACTION_DB_TYPE_MODIFY_BALANCE {
if transaction.CategoryId != 0 {