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
This commit is contained in:
Koen van Staveren
2024-10-21 23:23:09 +02:00
committed by GitHub
parent a3256f5686
commit a91a8859ab
3 changed files with 21 additions and 4 deletions

View File

@@ -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);
}),
);
}

View File

@@ -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;

View File

@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [UnderKoen]
---
Fix category being set on off-budget accounts