Skip to content

Commit

Permalink
enhance: allow prefix for budget templates (#4032)
Browse files Browse the repository at this point in the history
* enhance: allow prefix for budget templates

for example:
Prime video: #template $10

* chore: note

* chore: fix test

* chore: move prefix to template-notes.ts
  • Loading branch information
UnderKoen authored Jan 9, 2025
1 parent 6111f94 commit daca767
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/loot-core/src/server/budget/goal-template.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
20 changes: 20 additions & 0 deletions packages/loot-core/src/server/budget/template-notes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/loot-core/src/server/budget/template-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/4032.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [UnderKoen]
---

Allow note prefixes in budget templates.

0 comments on commit daca767

Please sign in to comment.