From 2c9d33f671519333a25eca05866567d063e8aaa4 Mon Sep 17 00:00:00 2001 From: shall0pass <20625555+shall0pass@users.noreply.github.com> Date: Fri, 15 Sep 2023 15:15:46 -0500 Subject: [PATCH] clear goal if template removed --- .../src/server/budget/goaltemplates.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/loot-core/src/server/budget/goaltemplates.ts b/packages/loot-core/src/server/budget/goaltemplates.ts index 7ecf4658984..1498fc91a4d 100644 --- a/packages/loot-core/src/server/budget/goaltemplates.ts +++ b/packages/loot-core/src/server/budget/goaltemplates.ts @@ -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); } @@ -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,