From df74e6ddd144a300dc8e3b9e91b3d1b5a760fd8a Mon Sep 17 00:00:00 2001 From: shall0pass <20625555+shall0pass@users.noreply.github.com> Date: Fri, 30 Jun 2023 16:00:51 -0500 Subject: [PATCH] Goals: Add recurring schedule support (#1193) Add recurring schedule support. To test: use the schedule keyword with a daily or weekly recurring schedule. --- .../src/server/budget/goaltemplates.ts | 20 +++++++++++++++++++ upcoming-release-notes/1193.md | 6 ++++++ 2 files changed, 26 insertions(+) create mode 100644 upcoming-release-notes/1193.md diff --git a/packages/loot-core/src/server/budget/goaltemplates.ts b/packages/loot-core/src/server/budget/goaltemplates.ts index d7bb126eb..fef46900f 100644 --- a/packages/loot-core/src/server/budget/goaltemplates.ts +++ b/packages/loot-core/src/server/budget/goaltemplates.ts @@ -533,11 +533,31 @@ async function applyCategoryTemplate( dateCond, monthUtils._parse(current_month), ); + + let isRepeating = + Object(dateCond.value) === dateCond.value && + 'frequency' in dateCond.value; + let num_months = monthUtils.differenceInCalendarMonths( next_date_string, current_month, ); + if (isRepeating) { + let monthlyTarget = 0; + let next_month = monthUtils.addMonths(current_month, num_months + 1); + let next_date = getNextDate( + dateCond, + monthUtils._parse(current_month), + ); + while (next_date < next_month) { + monthlyTarget += amountCond.value; + next_date = monthUtils.addDays(next_date, 1); + next_date = getNextDate(dateCond, monthUtils._parse(next_date)); + } + amountCond.value = monthlyTarget; + } + if (template.full === true) { if (num_months === 1) { to_budget = -getScheduledAmount(amountCond.value); diff --git a/upcoming-release-notes/1193.md b/upcoming-release-notes/1193.md new file mode 100644 index 000000000..b8c9268cc --- /dev/null +++ b/upcoming-release-notes/1193.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [shall0pass] +--- + +Goals: Schedule keyword supports daily or weekly recurring schedules -- GitLab