From bb1a4747f5d44f2706d577c1dfd0e144c4ee4bc6 Mon Sep 17 00:00:00 2001
From: shall0pass <20625555+shall0pass@users.noreply.github.com>
Date: Tue, 30 May 2023 14:24:21 -0500
Subject: [PATCH] Goals: Schedule include spent value in calculation (#1049)

This adds back the functionality, which was inadvertantly removed, that
includes the already spent column in the calculation when the template
is run.

Some transactions may be posted to the account prior to running the
templates and would result incorrect budgeted amounts.

---------

Co-authored-by: Jed Fox <git@jedfox.com>
---
 packages/loot-core/src/server/budget/goaltemplates.ts | 1 +
 upcoming-release-notes/1049.md                        | 6 ++++++
 2 files changed, 7 insertions(+)
 create mode 100644 upcoming-release-notes/1049.md

diff --git a/packages/loot-core/src/server/budget/goaltemplates.ts b/packages/loot-core/src/server/budget/goaltemplates.ts
index 9fcbdeb4c..66644df6e 100644
--- a/packages/loot-core/src/server/budget/goaltemplates.ts
+++ b/packages/loot-core/src/server/budget/goaltemplates.ts
@@ -541,6 +541,7 @@ async function applyCategoryTemplate(
             !priority
           ) {
             to_budget += diff;
+            if (l === template_lines.length - 1) to_budget -= spent;
           } else {
             if (budgetAvailable > 0) to_budget = budgetAvailable;
             errors.push(`Insufficient funds.`);
diff --git a/upcoming-release-notes/1049.md b/upcoming-release-notes/1049.md
new file mode 100644
index 000000000..ab841f69d
--- /dev/null
+++ b/upcoming-release-notes/1049.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [shall0pass]
+---
+
+Goals Schedule - Include spent in calculation
\ No newline at end of file
-- 
GitLab