Skip to content

Commit

Permalink
[Goals] fix how goal values are calculated (#3817)
Browse files Browse the repository at this point in the history
* fix how goals are calculated

* lint, note

* note
  • Loading branch information
youngcw authored Nov 11, 2024
1 parent 0c94214 commit 57ac062
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
23 changes: 13 additions & 10 deletions packages/loot-core/src/server/budget/categoryTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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 amount
private isLongGoal: boolean = null; //defaulting the goals to null so templates can be unset
private goalAmount: number = null;
private fromLastMonth = 0; // leftover from last month
Expand Down Expand Up @@ -265,7 +268,7 @@ export class CategoryTemplate {
this.goalAmount = amountToInteger(this.goals[0].amount);
return;
}
this.goalAmount = this.toBudgetAmount;
this.goalAmount = this.fullAmount;
}

//-----------------------------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions packages/loot-core/src/server/budget/goaltemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,13 @@ 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,
availStart,
);
availBudget -= ret;
}
if (availBudget <= 0) {
break;
}
}
// run limits
catObjects.forEach(o => {
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3817.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [youngcw]
---

Fix template goals after recent rewrite

0 comments on commit 57ac062

Please sign in to comment.