From a91a8859ab65013c9f64567f91d7974079893019 Mon Sep 17 00:00:00 2001 From: Koen van Staveren Date: Mon, 21 Oct 2024 23:23:09 +0200 Subject: [PATCH] feat: fix categories being set on offbudget transactions (#3705) * chore: release note * feat: fix categories being set on offbudget transactions * fix: #2266 * fix: small mistake * chore: update comment --- .../loot-core/src/server/accounts/transactions.ts | 8 +++++++- packages/loot-core/src/server/accounts/transfer.ts | 11 ++++++++--- upcoming-release-notes/3705.md | 6 ++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 upcoming-release-notes/3705.md diff --git a/packages/loot-core/src/server/accounts/transactions.ts b/packages/loot-core/src/server/accounts/transactions.ts index a056daac11..c91d0d95f0 100644 --- a/packages/loot-core/src/server/accounts/transactions.ts +++ b/packages/loot-core/src/server/accounts/transactions.ts @@ -77,7 +77,13 @@ export async function batchUpdateTransactions({ await batchMessages(async () => { if (added) { addedIds = await Promise.all( - added.map(async t => db.insertTransaction(t)), + added.map(async t => { + const account = accounts.find(acct => acct.id === t.account); + if (account.offbudget === 1) { + t.category = null; + } + return db.insertTransaction(t); + }), ); } diff --git a/packages/loot-core/src/server/accounts/transfer.ts b/packages/loot-core/src/server/accounts/transfer.ts index 04545bf785..f9c8104837 100644 --- a/packages/loot-core/src/server/accounts/transfer.ts +++ b/packages/loot-core/src/server/accounts/transfer.ts @@ -26,11 +26,16 @@ async function clearCategory(transaction, transferAcct) { [transferAcct], ); - // We should clear the category to make sure it's not being - // accounted for in the budget, unless it should be in the case of - // transferring from an on-budget to off-budget account + // If the transfer is between two on-budget or two off-budget accounts, + // we should clear the category, because the category is not relevant if (fromOffBudget === toOffBudget) { await db.updateTransaction({ id: transaction.id, category: null }); + if (transaction.transfer_id) { + await db.updateTransaction({ + id: transaction.transfer_id, + category: null, + }); + } return true; } return false; diff --git a/upcoming-release-notes/3705.md b/upcoming-release-notes/3705.md new file mode 100644 index 0000000000..d959e9cd07 --- /dev/null +++ b/upcoming-release-notes/3705.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [UnderKoen] +--- + +Fix category being set on off-budget accounts