Skip to content

A local-first personal finance app

fix: preserve schedule link when merging transactions (#7177)

okxint1d0281025db5
diff --git a/packages/loot-core/src/server/transactions/merge.test.ts b/packages/loot-core/src/server/transactions/merge.test.ts
index 08972fabb8..cc435630d5 100644
--- a/packages/loot-core/src/server/transactions/merge.test.ts
+++ b/packages/loot-core/src/server/transactions/merge.test.ts
@@ -284,6 +284,59 @@ describe('Merging success', () => {
});
});
+ it('preserves schedule link from dropped transaction when kept transaction has none', async () => {
+ const t1 = await db.insertTransaction({
+ account: 'one',
+ amount: 5,
+ date: '2025-01-01',
+ imported_id: 'imported_1',
+ });
+ const t2 = await db.insertTransaction({
+ ...transaction2,
+ schedule: 'schedule-1',
+ });
+
+ expect(await mergeTransactions([{ id: t1 }, { id: t2 }])).toBe(t1);
+ const transactions = await getAllTransactions();
+ expect(transactions.length).toBe(1);
+ expect(transactions[0].schedule).toBe('schedule-1');
+ });
+
+ it('preserves schedule link from kept transaction when both have schedules', async () => {
+ const t1 = await db.insertTransaction({
+ ...transaction1,
+ imported_id: 'imported_1',
+ schedule: 'schedule-keep',
+ });
+ const t2 = await db.insertTransaction({
+ ...transaction2,
+ schedule: 'schedule-drop',
+ });
+
+ expect(await mergeTransactions([{ id: t1 }, { id: t2 }])).toBe(t1);
+ const transactions = await getAllTransactions();
+ expect(transactions.length).toBe(1);
+ expect(transactions[0].schedule).toBe('schedule-keep');
+ });
+
+ it('preserves schedule link when merging manual scheduled with banksynced', async () => {
+ // Manual transaction linked to a schedule
+ const t1 = await db.insertTransaction({
+ ...transaction1,
+ schedule: 'schedule-1',
+ });
+ // Bank-synced transaction (kept due to imported_id priority)
+ const t2 = await db.insertTransaction({
+ ...transaction2,
+ imported_id: 'imported_2',
+ });
+
+ expect(await mergeTransactions([{ id: t1 }, { id: t2 }])).toBe(t2);
+ const transactions = await getAllTransactions();
+ expect(transactions.length).toBe(1);
+ expect(transactions[0].schedule).toBe('schedule-1');
+ });
+
it('preserves split categories when merging split transaction with uncategorized imported transaction', async () => {
// Create a manual transaction with splits
const manualParent = await db.insertTransaction({
diff --git a/packages/loot-core/src/server/transactions/merge.ts b/packages/loot-core/src/server/transactions/merge.ts
index 5abc37bb36..53f4755f54 100644
--- a/packages/loot-core/src/server/transactions/merge.ts
+++ b/packages/loot-core/src/server/transactions/merge.ts
@@ -81,6 +81,7 @@ export async function mergeTransactions(
notes: keep.notes || drop.notes,
cleared: keep.cleared || drop.cleared,
reconciled: keep.reconciled || drop.reconciled,
+ schedule: keep.schedule || drop.schedule,
} as unknown as TransactionEntity);
} else {
// Normal merge without subtransactions
@@ -91,6 +92,7 @@ export async function mergeTransactions(
notes: keep.notes || drop.notes,
cleared: keep.cleared || drop.cleared,
reconciled: keep.reconciled || drop.reconciled,
+ schedule: keep.schedule || drop.schedule,
} as TransactionEntity);
}
diff --git a/upcoming-release-notes/7177.md b/upcoming-release-notes/7177.md
new file mode 100644
index 0000000000..a0ce0c65a9
--- /dev/null
+++ b/upcoming-release-notes/7177.md
@@ -0,0 +1,6 @@
+---
+category: Bugfixes
+authors: [okxint]
+---
+
+Fix schedule link being lost when merging transactions