A local-first personal finance app
[Goals]: fix stacked templates (#4120)
youngcw629b001c01f5
diff --git a/packages/loot-core/src/server/budget/categoryTemplate.ts b/packages/loot-core/src/server/budget/categoryTemplate.tsindex 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 linefor (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 neededconst 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 limitdiff --git a/upcoming-release-notes/4120.md b/upcoming-release-notes/4120.mdnew file mode 100644index 0000000000..b6e67109c4--- /dev/null+++ b/upcoming-release-notes/4120.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [youngcw]+---++Fixed stacked templates with priorities