diff --git a/pkg/api/transactions.go b/pkg/api/transactions.go
index 025871a9..7efbb289 100644
--- a/pkg/api/transactions.go
+++ b/pkg/api/transactions.go
@@ -809,7 +809,7 @@ func (a *TransactionsApi) TransactionCreateHandler(c *core.WebContext) (any, *er
return nil, errs.ErrTransactionTypeInvalid
}
- if transactionCreateReq.Type == models.TRANSACTION_TYPE_MODIFY_BALANCE && transactionCreateReq.CategoryId > 0 {
+ if transactionCreateReq.Type == models.TRANSACTION_TYPE_MODIFY_BALANCE && transactionCreateReq.CategoryId != 0 {
log.Warnf(c, "[transactions.TransactionCreateHandler] balance modification transaction cannot set category id")
return nil, errs.ErrBalanceModificationTransactionCannotSetCategory
}
@@ -957,6 +957,14 @@ func (a *TransactionsApi) TransactionModifyHandler(c *core.WebContext) (any, *er
return nil, errs.ErrTransactionTypeInvalid
}
+ if transaction.Type == models.TRANSACTION_DB_TYPE_MODIFY_BALANCE && transactionModifyReq.CategoryId != 0 {
+ log.Warnf(c, "[transactions.TransactionModifyHandler] balance modification transaction cannot set category id")
+ return nil, errs.ErrBalanceModificationTransactionCannotSetCategory
+ } else if transaction.Type != models.TRANSACTION_DB_TYPE_MODIFY_BALANCE && transactionModifyReq.CategoryId == 0 {
+ log.Warnf(c, "[transactions.TransactionModifyHandler] non-balance modification transaction must set category id")
+ return nil, errs.ErrIncompleteOrIncorrectSubmission
+ }
+
allTransactionTagIds, err := a.transactionTags.GetAllTagIdsOfTransactions(c, uid, []int64{transaction.TransactionId})
if err != nil {
@@ -1498,7 +1506,7 @@ func (a *TransactionsApi) TransactionImportHandler(c *core.WebContext) (any, *er
return nil, errs.ErrTransactionTypeInvalid
}
- if transactionCreateReq.Type == models.TRANSACTION_TYPE_MODIFY_BALANCE && transactionCreateReq.CategoryId > 0 {
+ if transactionCreateReq.Type == models.TRANSACTION_TYPE_MODIFY_BALANCE && transactionCreateReq.CategoryId != 0 {
log.Warnf(c, "[transactions.TransactionImportHandler] balance modification transaction \"index:%d\" cannot set category id", i)
return nil, errs.ErrBalanceModificationTransactionCannotSetCategory
}
diff --git a/pkg/services/transactions.go b/pkg/services/transactions.go
index ad7a6488..032cdea7 100644
--- a/pkg/services/transactions.go
+++ b/pkg/services/transactions.go
@@ -1002,7 +1002,7 @@ func (s *TransactionService) ModifyTransaction(c core.Context, transaction *mode
return errs.ErrBalanceModificationTransactionCannotChangeAccountId
}
- if transaction.RelatedAccountAmount != oldTransaction.RelatedAccountAmount {
+ if transaction.Amount != oldTransaction.Amount && transaction.RelatedAccountAmount != oldTransaction.RelatedAccountAmount {
sourceAccount.UpdatedUnixTime = time.Now().Unix()
updatedRows, err := sess.ID(sourceAccount.AccountId).SetExpr("balance", fmt.Sprintf("balance-(%d)+(%d)", oldTransaction.RelatedAccountAmount, transaction.RelatedAccountAmount)).Cols("updated_unix_time").Where("uid=? AND deleted=?", sourceAccount.Uid, false).Update(sourceAccount)
diff --git a/src/models/transaction.ts b/src/models/transaction.ts
index 6b0c04e2..3f3df713 100644
--- a/src/models/transaction.ts
+++ b/src/models/transaction.ts
@@ -246,9 +246,15 @@ export class Transaction implements TransactionInfoResponse {
}
public toModifyRequest(actualTime?: number): TransactionModifyRequest {
+ let categoryId = this.getCategoryId();
+
+ if (this.type === TransactionType.ModifyBalance) {
+ categoryId = '0';
+ }
+
return {
id: this.id,
- categoryId: this.getCategoryId(),
+ categoryId: categoryId,
time: actualTime ? actualTime : this.time,
utcOffset: this.utcOffset,
sourceAccountId: this.sourceAccountId,
diff --git a/src/stores/transaction.ts b/src/stores/transaction.ts
index 4fb36a23..d99f2382 100644
--- a/src/stores/transaction.ts
+++ b/src/stores/transaction.ts
@@ -1050,7 +1050,11 @@ export const useTransactionsStore = defineStore('transactions', () => {
if (transaction.type !== TransactionType.Expense &&
transaction.type !== TransactionType.Income &&
- transaction.type !== TransactionType.Transfer) {
+ transaction.type !== TransactionType.Transfer &&
+ transaction.type !== TransactionType.ModifyBalance) {
+ reject({ message: 'An error occurred' });
+ return;
+ } else if (!isEdit && transaction.type === TransactionType.ModifyBalance) {
reject({ message: 'An error occurred' });
return;
}
diff --git a/src/views/desktop/transactions/list/dialogs/EditDialog.vue b/src/views/desktop/transactions/list/dialogs/EditDialog.vue
index 78dc61ca..e1fc5a7c 100644
--- a/src/views/desktop/transactions/list/dialogs/EditDialog.vue
+++ b/src/views/desktop/transactions/list/dialogs/EditDialog.vue
@@ -480,7 +480,7 @@
{{ tt('Edit') }}
diff --git a/src/views/mobile/transactions/ListPage.vue b/src/views/mobile/transactions/ListPage.vue
index 32e967b6..a235bd49 100644
--- a/src/views/mobile/transactions/ListPage.vue
+++ b/src/views/mobile/transactions/ListPage.vue
@@ -299,7 +299,7 @@
@click="duplicate(transaction)">