Skip to content

A local-first personal finance app

[AI] Fix incorrect schedule value when saving full amount (#8085)

Mats Nilsson56dc32ca69f5
diff --git a/packages/loot-core/src/server/budget/schedule-template.test.ts b/packages/loot-core/src/server/budget/schedule-template.test.ts
index 520b10d6ec..21ab50ca95 100644
--- a/packages/loot-core/src/server/budget/schedule-template.test.ts
+++ b/packages/loot-core/src/server/budget/schedule-template.test.ts
@@ -273,6 +273,50 @@ describe('runSchedule', () => {
defaultCurrency,
);
expect(result.to_budget).toBe(0);
+ expect(result.perScheduleMonthly.get('Insurance')).toBeUndefined();
+ });
+
+ it('only attributes contribution to schedules occurring this month when full: true is used', async () => {
+ const template_lines = [
+ {
+ type: 'schedule',
+ name: 'Schedule A',
+ full: true,
+ directive: 'template',
+ priority: 0,
+ } as const,
+ {
+ type: 'schedule',
+ name: 'Schedule B',
+ full: true,
+ directive: 'template',
+ priority: 0,
+ } as const,
+ ];
+ mockSchedulesByName({
+ 'Schedule A': {
+ spec: { start: '2024-08-01', amount: -10000, frequency: 'monthly' },
+ },
+ 'Schedule B': {
+ spec: { start: '2024-09-01', amount: -20000, frequency: 'monthly' },
+ },
+ });
+
+ const result = await runSchedule(
+ template_lines,
+ '2024-08-01',
+ 0,
+ 0,
+ 0,
+ 0,
+ [],
+ defaultCategory,
+ defaultCurrency,
+ );
+
+ expect(result.to_budget).toBe(10000);
+ expect(result.perScheduleMonthly.get('Schedule A')).toBe(10000);
+ expect(result.perScheduleMonthly.get('Schedule B')).toBeUndefined();
});
it('applies a percent adjustment to the schedule amount', async () => {
diff --git a/packages/loot-core/src/server/budget/schedule-template.ts b/packages/loot-core/src/server/budget/schedule-template.ts
index c5a1501989..4b4c23bd84 100644
--- a/packages/loot-core/src/server/budget/schedule-template.ts
+++ b/packages/loot-core/src/server/budget/schedule-template.ts
@@ -372,7 +372,11 @@ export async function runSchedule(
numSubMonthly > 0)
) {
to_budget += Math.round(totalPayMonthOf + totalSinkingBaseContribution);
- for (const c of t_payMonthOf) addContribution(c.name, c.target);
+ for (const c of t_payMonthOf) {
+ if (c.num_months === 0) {
+ addContribution(c.name, c.target);
+ }
+ }
for (const c of t_sinking) {
addContribution(c.name, getMonthlyBaseContribution(c));
}
@@ -386,7 +390,11 @@ export async function runSchedule(
} else {
to_budget += Math.round(totalPayMonthOf + totalSinkingContribution);
}
- for (const c of t_payMonthOf) addContribution(c.name, c.target);
+ for (const c of t_payMonthOf) {
+ if (c.num_months === 0) {
+ addContribution(c.name, c.target);
+ }
+ }
for (const [name, amount] of sinkingPerSchedule) {
addContribution(name, amount);
}
diff --git a/upcoming-release-notes/8085.md b/upcoming-release-notes/8085.md
new file mode 100644
index 0000000000..3b036a59c7
--- /dev/null
+++ b/upcoming-release-notes/8085.md
@@ -0,0 +1,6 @@
+---
+category: Bugfixes
+authors: [mnil]
+---
+
+Fix incorrect schedule value when saving full amount for a yearly schedule.