Skip to content

A local-first personal finance app

enhance: allow prefix for budget templates (#4032)

Koen van Staverendaca767808cc
diff --git a/packages/loot-core/src/server/budget/goal-template.pegjs b/packages/loot-core/src/server/budget/goal-template.pegjs
index 2cda62bdb6..3d78ada8fb 100644
--- a/packages/loot-core/src/server/budget/goal-template.pegjs
+++ b/packages/loot-core/src/server/budget/goal-template.pegjs
@@ -35,11 +35,11 @@ repeat 'repeat interval'
/ 'year'i { return { annual: true }}
/ years: positive _ 'years'i { return { annual: true, repeat: +years }}
-limit = _? upTo _ amount: amount _ 'per week starting'i _ start:date _? hold:hold?
+limit = _? upTo _ amount: amount _ 'per week starting'i _ start:date _? hold:hold?
{ return {amount: amount, hold: hold, period: 'weekly', start: start }}
/ _? upTo _ amount: amount _ 'per day'i _? hold: hold?
{ return {amount: amount, hold: hold, period: 'daily', start:null }}
- / _? upTo _ amount: amount _? hold: hold?
+ / _? upTo _ amount: amount _? hold: hold?
{ return {amount: amount, hold: hold, period: 'monthly', start:null }}
percentOf = percent:percent _ of _ 'previous'i _ { return { percent: percent, prev: true}}
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 a799b93944..1d036c9273 100644
--- a/packages/loot-core/src/server/budget/template-notes.test.ts
+++ b/packages/loot-core/src/server/budget/template-notes.test.ts
@@ -73,6 +73,26 @@ describe('storeTemplates', () => {
},
],
},
+ {
+ description:
+ 'Stores template when prefix is used with valid template notes',
+ mockTemplateNotes: [
+ {
+ id: 'cat1',
+ name: 'Category 1',
+ note: 'test: #template 12',
+ },
+ ],
+ expectedTemplates: [
+ {
+ type: 'simple',
+ monthly: 12,
+ limit: null,
+ priority: 0,
+ directive: 'template',
+ },
+ ],
+ },
{
description:
'Stores templates for categories with valid goal directive template notes',
diff --git a/packages/loot-core/src/server/budget/template-notes.ts b/packages/loot-core/src/server/budget/template-notes.ts
index 4141ec3dc0..a619a90a15 100644
--- a/packages/loot-core/src/server/budget/template-notes.ts
+++ b/packages/loot-core/src/server/budget/template-notes.ts
@@ -79,7 +79,7 @@ async function getCategoriesWithTemplates(): Promise<CategoryWithTemplates[]> {
const parsedTemplates: Template[] = [];
note.split('\n').forEach(line => {
- const trimmedLine = line.trim();
+ const trimmedLine = line.substring(line.indexOf('#')).trim();
if (
!trimmedLine.startsWith(TEMPLATE_PREFIX) &&
diff --git a/upcoming-release-notes/4032.md b/upcoming-release-notes/4032.md
new file mode 100644
index 0000000000..4c3d2e0f87
--- /dev/null
+++ b/upcoming-release-notes/4032.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [UnderKoen]
+---
+
+Allow note prefixes in budget templates.