Skip to content

Commit

Permalink
[Goals] Schedule top off amount (#2404)
Browse files Browse the repository at this point in the history
* add log messages to schedule templates

* log the included schedules

* more log output

* use a negate filter for sinking funds

* carve out a top out exception if no sinking funds

* note
  • Loading branch information
shall0pass authored Mar 4, 2024
1 parent 601c9aa commit 98c17bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
46 changes: 19 additions & 27 deletions packages/loot-core/src/server/budget/goals/goalsSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,36 +186,22 @@ export async function goalsSchedule(
const t = await createScheduleList(template, current_month, category);
errors = errors.concat(t.errors);

const t_payMonthOf = t.t.filter(
c =>
c.full ||
(c.target_frequency === 'monthly' &&
c.target_interval === 1 &&
c.num_months === 0) ||
(c.target_frequency === 'weekly' &&
c.target_interval >= 0 &&
c.num_months === 0) ||
c.target_frequency === 'daily' ||
isReflectBudget(),
);
const isPayMonthOf = c =>
c.full ||
(c.target_frequency === 'monthly' &&
c.target_interval === 1 &&
c.num_months === 0) ||
(c.target_frequency === 'weekly' &&
c.target_interval >= 0 &&
c.num_months === 0) ||
c.target_frequency === 'daily' ||
isReflectBudget();

const t_payMonthOf = t.t.filter(isPayMonthOf);
const t_sinking = t.t
.filter(
c =>
(!c.full &&
c.target_frequency === 'monthly' &&
c.target_interval > 1) ||
(!c.full &&
c.target_frequency === 'monthly' &&
c.num_months > 0 &&
c.target_interval === 1) ||
(!c.full && c.target_frequency === 'yearly') ||
(!c.full && c.target_frequency === undefined),
)
.filter(c => !isPayMonthOf(c))
.sort((a, b) => a.next_date_string.localeCompare(b.next_date_string));

const totalPayMonthOf = await getPayMonthOfTotal(t_payMonthOf);

const totalSinking = await getSinkingTotal(t_sinking);
const totalSinkingBaseContribution =
await getSinkingBaseContributionTotal(t_sinking);
Expand All @@ -228,7 +214,13 @@ export async function goalsSchedule(
remainder,
last_month_balance,
);
to_budget += Math.round(totalPayMonthOf + totalSinkingContribution);
if (t_sinking.length === 0) {
to_budget +=
Math.round(totalPayMonthOf + totalSinkingContribution) -
last_month_balance;
} else {
to_budget += Math.round(totalPayMonthOf + totalSinkingContribution);
}
}
}
return { to_budget, errors, remainder, scheduleFlag };
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2404.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [shall0pass]
---

[Goals] If no sinking funds are used, apply existing category balance to simple schedules to 'top off' the category.

0 comments on commit 98c17bd

Please sign in to comment.