A local-first personal finance app
Template: Apply schedule template only on needed month (#1052)
youngcw5f38b579fe24
diff --git a/packages/loot-core/src/server/budget/goal-template.pegjs b/packages/loot-core/src/server/budget/goal-template.pegjsindex 26b7ac630c..2efb87f544 100644--- a/packages/loot-core/src/server/budget/goal-template.pegjs+++ b/packages/loot-core/src/server/budget/goal-template.pegjs@@ -1,11 +1,9 @@-// https://peggyjs.org-expr- = priority: priority? _? percent: percent _ of _ category: name+ = priority: priority? percent: percent _ of _ category: name{ return { type: 'percentage', percent: +percent, category, priority: +priority }}- / priority: priority? _? amount: amount _ repeatEvery _ weeks: weekCount _ starting _ starting: date limit: limit?+ / priority: priority? amount: amount _ repeatEvery _ weeks: weekCount _ starting _ starting: date limit: limit?{ return { type: 'week', amount, weeks, starting, limit, priority: +priority }}- / priority: priority? _? amount: amount _ by _ month: month from: spendFrom? repeat: (_ repeatEvery _ repeat)?+ / priority: priority? amount: amount _ by _ month: month from: spendFrom? repeat: (_ repeatEvery _ repeat)?{ return {type: from ? 'spend' : 'by',amount,@@ -14,12 +12,13 @@ exprfrom,priority: +priority} }- / priority: priority? _? monthly: amount limit: limit?- { return { type: 'simple', monthly, limit, priority: +priority } }- / priority: priority? _? limit: limit+ / priority: priority? monthly: amount limit: limit?+ { return { type: 'simple', monthly, limit, priority: +priority } }+ / priority: priority? limit: limit{ return { type: 'simple', limit , priority: +priority } }- / priority: priority? _? schedule _ name: name- { return { type: 'schedule', name, priority: +priority } }+ / priority: priority? schedule _ full:full? name: name+ { return { type: 'schedule', name, priority: +priority, full } }+repeat 'repeat interval'= 'month'i { return { annual: false } }@@ -28,7 +27,7 @@ repeat 'repeat interval'/ years: d _ 'years'i { return { annual: true, repeat: +years } }limit = _? upTo _ amount: amount _ 'hold'i { return {amount: amount, hold: true } }- / _? upTo _ amount: amount { return {amount: amount, hold: false } }+ / _? upTo _ amount: amount { return {amount: amount, hold: false } }weekCount@@ -45,6 +44,7 @@ repeatEvery = 'repeat'i _ 'every'istarting = 'starting'iupTo = 'up'i _ 'to'ischedule = 'schedule'i+full = 'full'i _ {return true}priority = '-'i number: number _ {return number}_ 'space' = ' '+@@ -59,3 +59,4 @@ date = $(month '-' day)currencySymbol 'currency symbol' = symbol: . & { return /\p{Sc}/u.test(symbol) }name 'Name' = $([^\r\n\t]+)+diff --git a/packages/loot-core/src/server/budget/goaltemplates.ts b/packages/loot-core/src/server/budget/goaltemplates.tsindex 992acae7a9..9cad8ffb7c 100644--- a/packages/loot-core/src/server/budget/goaltemplates.ts+++ b/packages/loot-core/src/server/budget/goaltemplates.ts@@ -489,9 +489,6 @@ async function applyCategoryTemplate(}break;}- case 'error':- return { errors };- default:case 'schedule': {let { id: schedule_id } = await db.first('SELECT id FROM schedules WHERE name = ?',@@ -506,6 +503,14 @@ async function applyCategoryTemplate(new Date(next_date_string),current_month,);++ if (template.full === true) {+ if (num_months === 1) {+ to_budget = -getScheduledAmount(amountCond.value);+ }+ break;+ }+if (l === 0) remainder = last_month_balance;remainder = -getScheduledAmount(amountCond.value) - remainder;let target = 0;@@ -537,6 +542,9 @@ async function applyCategoryTemplate(}break;}+ case 'error':+ return { errors };+ default:}}diff --git a/upcoming-release-notes/1052.md b/upcoming-release-notes/1052.mdnew file mode 100644index 0000000000..9568abde85--- /dev/null+++ b/upcoming-release-notes/1052.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [youngcw]+---++Templates: Add option to only apply schedule template to the month of the schedule instead of spreading out the charge.