A local-first personal finance app
[AI] preserve category when making transfer between on/off-budget accounts (#9205)
devilking7x1c852e488289
diff --git a/packages/desktop-client/src/hooks/useTransactionBatchActions.ts b/packages/desktop-client/src/hooks/useTransactionBatchActions.tsindex f049647322..3c478ab6fc 100644--- a/packages/desktop-client/src/hooks/useTransactionBatchActions.ts+++ b/packages/desktop-client/src/hooks/useTransactionBatchActions.ts@@ -536,17 +536,37 @@ export function useTransactionBatchActions() {);const toPayee = payees.find(p => p.transfer_acct === toTrans.account);+ // Only clear the category when the transfer is between two accounts+ // of the same budget type (both on-budget or both off-budget),+ // because the category is not relevant for such transfers. A transfer+ // between an on-budget and an off-budget account represents money+ // entering/leaving the budget, so the category must be preserved.+ // This matches the server-side logic in clearCategory (transfer.ts).+ const { data: accounts } = await aqlQuery(+ q('accounts')+ .filter({ id: { $oneof: [fromTrans.account, toTrans.account] } })+ .select(['id', 'offbudget']),+ );+ const fromAccount = accounts.find(+ (a: { id: string; offbudget?: boolean }) =>+ a.id === fromTrans.account,+ );+ const toAccount = accounts.find(+ (a: { id: string; offbudget?: boolean }) => a.id === toTrans.account,+ );+ const clearCategory = fromAccount?.offbudget === toAccount?.offbudget;+const changes = {updated: [{...fromTrans,- category: null,+ ...(clearCategory ? { category: null } : {}),payee: toPayee?.id,transfer_id: toTrans.id,},{...toTrans,- category: null,+ ...(clearCategory ? { category: null } : {}),payee: fromPayee?.id,transfer_id: fromTrans.id,},diff --git a/upcoming-release-notes/9205.md b/upcoming-release-notes/9205.mdnew file mode 100644index 0000000000..8eca6eb459--- /dev/null+++ b/upcoming-release-notes/9205.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [devilking7x]+---++Preserve the category when making a transfer between on-budget and off-budget accounts