From 629b001c01f5234bf88cdb4a542d73d6be54392c Mon Sep 17 00:00:00 2001 From: youngcw Date: Mon, 13 Jan 2025 15:10:32 -0700 Subject: [PATCH] [Goals]: fix stacked templates (#4120) * fix stacked amounts * note/lint --- .../src/server/budget/categoryTemplate.ts | 22 +++++++++++-------- upcoming-release-notes/4120.md | 6 +++++ 2 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 upcoming-release-notes/4120.md diff --git a/packages/loot-core/src/server/budget/categoryTemplate.ts b/packages/loot-core/src/server/budget/categoryTemplate.ts index 2b6e467f9c..edde050a03 100644 --- a/packages/loot-core/src/server/budget/categoryTemplate.ts +++ b/packages/loot-core/src/server/budget/categoryTemplate.ts @@ -95,31 +95,32 @@ export class CategoryTemplate { let scheduleFlag = false; // switch on template type and calculate the amount for the line for (let i = 0; i < t.length; i++) { + let newBudget = 0; switch (t[i].type) { case 'simple': { - toBudget += this.runSimple(t[i], this.limitAmount); + newBudget = this.runSimple(t[i], this.limitAmount); break; } case 'copy': { - toBudget += await this.runCopy(t[i]); + newBudget = await this.runCopy(t[i]); break; } case 'week': { - toBudget += this.runWeek(t[i]); + newBudget = this.runWeek(t[i]); break; } case 'spend': { - toBudget += await this.runSpend(t[i]); + newBudget = await this.runSpend(t[i]); break; } case 'percentage': { - toBudget += await this.runPercentage(t[i], availStart); + newBudget = await this.runPercentage(t[i], availStart); break; } case 'by': { //TODO add the logic to run all of these at once or whatever is needed const ret = this.runBy(t[i], first, remainder); - toBudget += ret.ret; + newBudget = ret.ret; remainder = ret.remainder; first = false; break; @@ -140,18 +141,21 @@ export class CategoryTemplate { [], this.category, ); - toBudget = ret.to_budget; + // Schedules assume that its to budget value is the whole thing so this + // needs to remove the previous funds so they aren't double counted + newBudget = ret.to_budget - toBudget; remainder = ret.remainder; scheduleFlag = ret.scheduleFlag; break; } case 'average': { - toBudget += await this.runAverage(t[i]); + newBudget = await this.runAverage(t[i]); break; } } - available = available - toBudget; + available = available - newBudget; + toBudget += newBudget; } //check limit diff --git a/upcoming-release-notes/4120.md b/upcoming-release-notes/4120.md new file mode 100644 index 0000000000..b6e67109c4 --- /dev/null +++ b/upcoming-release-notes/4120.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [youngcw] +--- + +Fixed stacked templates with priorities