Skip to content

Commit

Permalink
clear goal if template removed
Browse files Browse the repository at this point in the history
  • Loading branch information
shall0pass committed Sep 15, 2023
1 parent ac4c3eb commit 2c9d33f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/loot-core/src/server/budget/goaltemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import { parse } from './goal-template.pegjs';

export async function applyTemplate({ month }) {
let category_templates = await getCategoryTemplates(null);
await resetCategoryTargets({ month });
return processTemplate(month, false, category_templates);
}

export async function overwriteTemplate({ month }) {
let category_templates = await getCategoryTemplates(null);
await resetCategoryTargets({ month });
return processTemplate(month, true, category_templates);
}

Expand Down Expand Up @@ -72,6 +74,21 @@ async function setCategoryTargets({ month, idealTemplate }) {
});
}

async function resetCategoryTargets({ month }) {
let categories = await db.all(
'SELECT * FROM v_categories WHERE tombstone = 0 AND hidden = 0',
);
await batchMessages(async () => {
categories.forEach(element => {
setGoal({
category: element.id,
goal: 0,
month: month,
});
});
});
}

async function processTemplate(
month,
force,
Expand Down

0 comments on commit 2c9d33f

Please sign in to comment.