From e5933ad8cde43802160f9f35237a4898b172610c Mon Sep 17 00:00:00 2001 From: Wizmaster <code@wizmaster.fr> Date: Wed, 15 May 2024 23:16:34 +0200 Subject: [PATCH] Don't update transaction date when importing manually (#2648) - Manual import should not override the transaction date as done with bank account sync --- packages/api/methods.test.ts | 28 ++++++++++++++----- .../loot-core/src/server/accounts/sync.ts | 1 - upcoming-release-notes/2648.md | 6 ++++ 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 upcoming-release-notes/2648.md diff --git a/packages/api/methods.test.ts b/packages/api/methods.test.ts index 7d14d5968..4a3cc0900 100644 --- a/packages/api/methods.test.ts +++ b/packages/api/methods.test.ts @@ -559,8 +559,8 @@ describe('API CRUD operations', () => { const accountId = await api.createAccount({ name: 'test-account' }, 0); let newTransaction = [ - { date: '2023-11-03', imported_id: '11', amount: 100 }, - { date: '2023-11-03', imported_id: '11', amount: 100 }, + { date: '2023-11-03', imported_id: '11', amount: 100, notes: 'notes' }, + { date: '2023-11-03', imported_id: '12', amount: 100, notes: '' }, ]; const addResult = await api.addTransactions(accountId, newTransaction, { @@ -583,8 +583,9 @@ describe('API CRUD operations', () => { expect(transactions).toHaveLength(2); newTransaction = [ - { date: '2023-12-03', imported_id: '11', amount: 100 }, - { date: '2023-12-03', imported_id: '22', amount: 200 }, + { date: '2023-12-03', imported_id: '11', amount: 100, notes: 'notes' }, + { date: '2023-12-03', imported_id: '12', amount: 100, notes: 'notes' }, + { date: '2023-12-03', imported_id: '22', amount: 200, notes: '' }, ]; const reconciled = await api.importTransactions(accountId, newTransaction); @@ -600,9 +601,22 @@ describe('API CRUD operations', () => { '2023-12-31', ); expect(transactions).toEqual( - expect.arrayContaining( - newTransaction.map(trans => expect.objectContaining(trans)), - ), + expect.arrayContaining([ + expect.objectContaining({ imported_id: '22', amount: 200 }), + ]), + ); + expect(transactions).toHaveLength(1); + + // confirm imported transactions update perfomed + transactions = await api.getTransactions( + accountId, + '2023-11-01', + '2023-11-30', + ); + expect(transactions).toEqual( + expect.arrayContaining([ + expect.objectContaining({ notes: 'notes', amount: 100 }), + ]), ); expect(transactions).toHaveLength(2); diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.ts index d8f919524..39f48bcdb 100644 --- a/packages/loot-core/src/server/accounts/sync.ts +++ b/packages/loot-core/src/server/accounts/sync.ts @@ -490,7 +490,6 @@ export async function reconcileTransactions( // Update the transaction const updates = { - ...(isBankSyncAccount ? {} : { date: trans.date }), imported_id: trans.imported_id || null, payee: existing.payee || trans.payee || null, category: existing.category || trans.category || null, diff --git a/upcoming-release-notes/2648.md b/upcoming-release-notes/2648.md new file mode 100644 index 000000000..6d76bca18 --- /dev/null +++ b/upcoming-release-notes/2648.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [Wizmaster] +--- + +Don't update transaction date when importing manually \ No newline at end of file -- GitLab