Skip to content

A local-first personal finance app

enhance: allow negatives in the budget template (#4028)

Koen van Staveren8976ffc256d5
diff --git a/packages/loot-core/src/server/budget/goal-template.pegjs b/packages/loot-core/src/server/budget/goal-template.pegjs
index fcf3201652..2cda62bdb6 100644
--- a/packages/loot-core/src/server/budget/goal-template.pegjs
+++ b/packages/loot-core/src/server/budget/goal-template.pegjs
@@ -70,7 +70,7 @@ _ 'space' = ' '+
d 'digit' = [0-9]
number 'number' = $(d+)
positive = $([1-9][0-9]*)
-amount 'amount' = currencySymbol? _? amount: $(d+ ('.' (d d?)?)?) { return +amount }
+amount 'amount' = currencySymbol? _? amount: $('-'?d+ ('.' (d d?)?)?) { return +amount }
percent 'percentage' = percent: $(d+ ('.' (d+)?)?) _? '%' { return +percent }
year 'year' = $(d d d d)
month 'month' = $(year '-' d d)
diff --git a/packages/loot-core/src/server/budget/template-notes.test.ts b/packages/loot-core/src/server/budget/template-notes.test.ts
index 7aaf6a99fc..a799b93944 100644
--- a/packages/loot-core/src/server/budget/template-notes.test.ts
+++ b/packages/loot-core/src/server/budget/template-notes.test.ts
@@ -53,6 +53,26 @@ describe('storeTemplates', () => {
},
],
},
+ {
+ description:
+ 'Stores negative templates for categories with valid template notes',
+ mockTemplateNotes: [
+ {
+ id: 'cat1',
+ name: 'Category 1',
+ note: '#template -103.23',
+ },
+ ],
+ expectedTemplates: [
+ {
+ type: 'simple',
+ monthly: -103.23,
+ limit: null,
+ priority: 0,
+ directive: 'template',
+ },
+ ],
+ },
{
description:
'Stores templates for categories with valid goal directive template notes',
diff --git a/upcoming-release-notes/4028.md b/upcoming-release-notes/4028.md
new file mode 100644
index 0000000000..095b844924
--- /dev/null
+++ b/upcoming-release-notes/4028.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [UnderKoen]
+---
+
+Allow negatives in budget templates.