Skip to content

A local-first personal finance app

don't unbudget goals

youngcw14c1d9f03bd6
diff --git a/packages/loot-core/src/server/budget/categoryTemplate.ts b/packages/loot-core/src/server/budget/categoryTemplate.ts
index 9dcd518070..a02b34d033 100644
--- a/packages/loot-core/src/server/budget/categoryTemplate.ts
+++ b/packages/loot-core/src/server/budget/categoryTemplate.ts
@@ -30,7 +30,12 @@ export class CategoryTemplate {
// Class interface
// set up the class and check all templates
- static async init(templates: Template[], category: CategoryEntity, month) {
+ static async init(
+ templates: Template[],
+ category: CategoryEntity,
+ month,
+ budgeted: number,
+ ) {
// get all the needed setup values
const lastMonthSheet = monthUtils.sheetForMonth(
monthUtils.subMonths(month, 1),
@@ -47,6 +52,7 @@ export class CategoryTemplate {
if (lastMonthBalance < 0 && !carryover) {
fromLastMonth = 0;
} else if (category.is_income) {
+ //for tracking budget
fromLastMonth = 0;
} else {
fromLastMonth = lastMonthBalance;
@@ -55,9 +61,23 @@ export class CategoryTemplate {
await CategoryTemplate.checkByAndScheduleAndSpend(templates, month);
await CategoryTemplate.checkPercentage(templates);
// call the private constructor
- return new CategoryTemplate(templates, category, month, fromLastMonth);
+ return new CategoryTemplate(
+ templates,
+ category,
+ month,
+ fromLastMonth,
+ budgeted,
+ );
}
+ getGoalOnly(): boolean {
+ // if there is only a goal
+ return (
+ this.templates.length == 0 &&
+ this.remainder.length == 0 &&
+ this.goals.length > 0
+ );
+ }
getPriorities(): number[] {
return this.priorities;
}
@@ -224,16 +244,19 @@ export class CategoryTemplate {
private limitAmount = 0;
private limitCheck = false;
private limitHold = false;
+ readonly previouslyBudgeted: number = 0;
private constructor(
templates: Template[],
category: CategoryEntity,
month: string,
fromLastMonth: number,
+ budgeted: number,
) {
this.category = category;
this.month = month;
this.fromLastMonth = fromLastMonth;
+ this.previouslyBudgeted = budgeted;
// sort the template lines into regular template, goals, and remainder templates
if (templates) {
templates.forEach(t => {
@@ -279,6 +302,7 @@ export class CategoryTemplate {
private runGoal() {
if (this.goals.length > 0) {
+ if (this.getGoalOnly()) this.toBudgetAmount = this.previouslyBudgeted;
this.isLongGoal = true;
this.goalAmount = amountToInteger(this.goals[0].amount);
return;
diff --git a/packages/loot-core/src/server/budget/goaltemplates.ts b/packages/loot-core/src/server/budget/goaltemplates.ts
index 7a4b00a30c..b5f358e3d0 100644
--- a/packages/loot-core/src/server/budget/goaltemplates.ts
+++ b/packages/loot-core/src/server/budget/goaltemplates.ts
@@ -164,15 +164,23 @@ async function processTemplate(
// gather needed priorities
// gather remainder weights
try {
- const obj = await CategoryTemplate.init(templates, category, month);
- availBudget += budgeted;
+ const obj = await CategoryTemplate.init(
+ templates,
+ category,
+ month,
+ budgeted,
+ );
+ // don't use the funds that are not from templates
+ let goalthing = obj.getGoalOnly();
+ if (!goalthing) {
+ availBudget += budgeted;
+ }
availBudget += obj.getLimitExcess();
const p = obj.getPriorities();
p.forEach(pr => priorities.push(pr));
remainderWeight += obj.getRemainderWeight();
catObjects.push(obj);
} catch (e) {
- //console.log(`${categories[i].name}: ${e}`);
errors.push(`${categories[i].name}: ${e.message}`);
}
@@ -183,7 +191,6 @@ async function processTemplate(
goal: null,
longGoal: null,
});
- //await setGoal({ month, category: id, goal: null, long_goal: null });
}
}