A local-first personal finance app
fix schedules not showing as paid (#8801)
Matt Fiddaman0f7957924934
diff --git a/packages/loot-core/src/server/schedules/app.test.ts b/packages/loot-core/src/server/schedules/app.test.tsindex 4c90047ea2..01bb3c0adc 100644--- a/packages/loot-core/src/server/schedules/app.test.ts+++ b/packages/loot-core/src/server/schedules/app.test.ts@@ -857,6 +857,99 @@ describe('schedule app', () => {}});+ it('keeps a schedule posted today paid for the rest of the day', async () => {+ // In tests `currentDay()` is fixed at 2017-01-01, so that is "today".+ MockDate.set(new Date(2016, 11, 31, 12));+ schedulesApp.startServices();++ try {+ const accountId = await db.insertAccount({+ name: 'Checking',+ offbudget: 0,+ closed: 0,+ });++ const id = await createSchedule({+ schedule: { posts_transaction: true },+ conditions: [+ {+ op: 'is',+ field: 'account',+ value: accountId,+ },+ {+ op: 'is',+ field: 'amount',+ value: -10000,+ },+ {+ op: 'is',+ field: 'date',+ value: {+ start: '2016-12-18',+ frequency: 'weekly',+ interval: 1,+ patterns: [],+ },+ },+ ],+ });+ const nextDateRow = await db.first<{+ id: string;+ }>('SELECT id FROM schedules_next_date WHERE schedule_id = ?', [id]);++ await db.update('schedules_next_date', {+ id: nextDateRow.id,+ local_next_date: 20170101,+ local_next_date_ts: Date.now(),+ base_next_date: 20170101,+ base_next_date_ts: Date.now(),+ });++ await advanceSchedulesService(true);++ const { data: transactions } = await aqlQuery(+ q('transactions')+ .filter({ schedule: id })+ .select(['date', 'amount'])+ .orderBy({ date: 'asc' }),+ );++ expect(+ transactions.map(({ date, amount }) => ({ date, amount })),+ ).toEqual([{ date: '2017-01-01', amount: -10000 }]);++ const {+ data: [schedule],+ } = await aqlQuery(q('schedules').filter({ id }).select(['next_date']));++ expect(schedule.next_date).toBe('2017-01-01');++ // A same-day re-run (e.g. offline retry) neither posts again nor+ // advances; the schedule stays paid on today's date. Advancement on+ // a later day is covered by the catch-up tests above.+ await advanceSchedulesService(true);++ const { data: transactionsAfter } = await aqlQuery(+ q('transactions')+ .filter({ schedule: id })+ .select(['date', 'amount'])+ .orderBy({ date: 'asc' }),+ );++ expect(transactionsAfter).toHaveLength(1);++ const {+ data: [scheduleAfter],+ } = await aqlQuery(q('schedules').filter({ id }).select(['next_date']));++ expect(scheduleAfter.next_date).toBe('2017-01-01');+ } finally {+ MockDate.reset();+ await schedulesApp.stopServices();+ }+ });+it('keeps a `set amount` action in sync when the amount is edited', async () => {MockDate.set(new Date(2016, 11, 31, 12));schedulesApp.startServices();diff --git a/packages/loot-core/src/server/schedules/app.ts b/packages/loot-core/src/server/schedules/app.tsindex 6b55a25b7c..e27ecd19e6 100644--- a/packages/loot-core/src/server/schedules/app.ts+++ b/packages/loot-core/src/server/schedules/app.ts@@ -716,6 +716,10 @@ export async function advanceSchedulesService(syncSuccess) {currentStatus === 'missed')) {if (currentStatus === 'paid') {+ if (currentSchedule.next_date === currentDay()) {+ break;+ }+const updatedSchedule =await advanceRecurringScheduleFromNextDate(currentSchedule);@@ -745,6 +749,11 @@ export async function advanceSchedulesService(syncSuccess) {break;}+ // do not skip schedules due today+ if (currentStatus === 'due') {+ break;+ }+if (!isRecurringSchedule(currentSchedule)) {break;}diff --git a/upcoming-release-notes/keep-posted-schedules-paid-today.md b/upcoming-release-notes/keep-posted-schedules-paid-today.mdnew file mode 100644index 0000000000..b666e071da--- /dev/null+++ b/upcoming-release-notes/keep-posted-schedules-paid-today.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [matt-fidd]+---++Keep automatically posted schedules visible as paid on the day they run instead of jumping straight to the next date