A local-first personal finance app
[Goals] fix how goal values are calculated (#3817)
youngcw57ac062edc62
diff --git a/packages/loot-core/src/server/budget/categoryTemplate.ts b/packages/loot-core/src/server/budget/categoryTemplate.tsindex 9a70e65578..c48a75245a 100644--- a/packages/loot-core/src/server/budget/categoryTemplate.ts+++ b/packages/loot-core/src/server/budget/categoryTemplate.ts@@ -134,18 +134,18 @@ export class CategoryTemplate {}}- // don't overbudget when using a priority- if (priority > 0 && toBudget > available) {- toBudget = available;- }available = available - toBudget;-- if (priority > 0 && available <= 0) {- break;- }}- this.toBudgetAmount += toBudget;+ // don't overbudget when using a priority+ if (priority > 0 && available < 0) {+ this.fullAmount += toBudget;+ toBudget = Math.max(0, toBudget + available);+ this.toBudgetAmount += toBudget;+ } else {+ this.fullAmount += toBudget;+ this.toBudgetAmount += toBudget;+ }return toBudget;}@@ -155,12 +155,14 @@ export class CategoryTemplate {}if (this.limitHold && this.fromLastMonth >= this.limitAmount) {const orig = this.toBudgetAmount;+ this.fullAmount = 0;this.toBudgetAmount = 0;return orig;}if (this.toBudgetAmount + this.fromLastMonth > this.limitAmount) {const orig = this.toBudgetAmount;this.toBudgetAmount = this.limitAmount - this.fromLastMonth;+ this.fullAmount = this.toBudgetAmount;return orig - this.toBudgetAmount;}return 0;@@ -200,6 +202,7 @@ export class CategoryTemplate {private priorities: number[] = [];private remainderWeight: number = 0;private toBudgetAmount: number = 0; // amount that will be budgeted by the templates+ private fullAmount: number = 0; // the full requested amountprivate isLongGoal: boolean = null; //defaulting the goals to null so templates can be unsetprivate goalAmount: number = null;private fromLastMonth = 0; // leftover from last month@@ -265,7 +268,7 @@ export class CategoryTemplate {this.goalAmount = amountToInteger(this.goals[0].amount);return;}- this.goalAmount = this.toBudgetAmount;+ this.goalAmount = this.fullAmount;}//-----------------------------------------------------------------------------diff --git a/packages/loot-core/src/server/budget/goaltemplates.ts b/packages/loot-core/src/server/budget/goaltemplates.tsindex a91516c215..27fd2aa485 100644--- a/packages/loot-core/src/server/budget/goaltemplates.ts+++ b/packages/loot-core/src/server/budget/goaltemplates.ts@@ -211,7 +211,6 @@ async function processTemplate(const availStart = availBudget;const p = priorities[pi];for (let i = 0; i < catObjects.length; i++) {- if (availBudget <= 0 && p > 0) break;const ret = await catObjects[i].runTemplatesForPriority(p,availBudget,@@ -219,9 +218,6 @@ async function processTemplate();availBudget -= ret;}- if (availBudget <= 0) {- break;- }}// run limitscatObjects.forEach(o => {diff --git a/upcoming-release-notes/3817.md b/upcoming-release-notes/3817.mdnew file mode 100644index 0000000000..66ac69a953--- /dev/null+++ b/upcoming-release-notes/3817.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [youngcw]+---++Fix template goals after recent rewrite