A local-first personal finance app
[Goals] Fix some schedule template regressions (#6610)
youngcw25ee19c1e197
diff --git a/packages/loot-core/src/server/budget/schedule-template.ts b/packages/loot-core/src/server/budget/schedule-template.tsindex 3d714d6aa9..3e9154d2f4 100644--- a/packages/loot-core/src/server/budget/schedule-template.ts+++ b/packages/loot-core/src/server/budget/schedule-template.ts@@ -20,7 +20,7 @@ type ScheduleTemplateTarget = {target: number;next_date_string: string;target_interval: number;- target_frequency: string;+ target_frequency: string | undefined;num_months: number;completed: number;full: boolean;@@ -238,6 +238,8 @@ function getSinkingBaseContributionTotal(t: ScheduleTemplateTarget[]) {monthlyAmount = schedule.target / intervalMonths;break;default:+ // default to same math as monthly for now for non-reoccuring+ monthlyAmount = schedule.target / schedule.target_interval;break;}total += monthlyAmount;@@ -275,17 +277,21 @@ export async function runSchedule(const isPayMonthOf = c =>c.full ||- (c.target_frequency === 'monthly' &&+ ((c.target_frequency === 'monthly' || !c.target_frequency) &&c.target_interval === 1 &&c.num_months === 0) ||(c.target_frequency === 'weekly' && c.target_interval <= 4) ||(c.target_frequency === 'daily' && c.target_interval <= 31) ||isReflectBudget();+ const isSubMonthly = c =>+ c.target_frequency === 'weekly' || c.target_frequency === 'daily';+const t_payMonthOf = t.t.filter(isPayMonthOf);const t_sinking = t.t.filter(c => !isPayMonthOf(c)).sort((a, b) => a.next_date_string.localeCompare(b.next_date_string));+ const numSubMonthly = t.t.filter(isSubMonthly).length;const totalPayMonthOf = getPayMonthOfTotal(t_payMonthOf);const totalSinking = getSinkingTotal(t_sinking);const totalSinkingBaseContribution =@@ -303,7 +309,8 @@ export async function runSchedule(balance >= totalSinking + totalPayMonthOf ||(lastMonthGoal < totalSinking + totalPayMonthOf &&lastMonthGoal !== 0 &&- balance >= lastMonthGoal)+ balance >= lastMonthGoal &&+ numSubMonthly > 0)) {to_budget += Math.round(totalPayMonthOf + totalSinkingBaseContribution);} else {diff --git a/upcoming-release-notes/6610.md b/upcoming-release-notes/6610.mdnew file mode 100644index 0000000000..e0f1b35a66--- /dev/null+++ b/upcoming-release-notes/6610.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [youngcw]+---++Fix schedule template regressions where categories are being underbudgeted and to improve functionality and user experience.