From 6a21f8e3de7fda25afe4345a0af3aad6d90d4966 Mon Sep 17 00:00:00 2001
From: Matiss Janis Aboltins <matiss@mja.lv>
Date: Sat, 22 Jun 2024 21:32:51 +0100
Subject: [PATCH] =?UTF-8?q?Revert=20"fix(#2562):=20Prevent=20transaction?=
 =?UTF-8?q?=20deduplication=20for=20imported=20transactio=E2=80=A6"=20(#29?=
 =?UTF-8?q?10)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../src/server/accounts/sync.test.ts          | 104 ------------------
 .../loot-core/src/server/accounts/sync.ts     |   9 +-
 upcoming-release-notes/2770.md                |   6 -
 3 files changed, 1 insertion(+), 118 deletions(-)
 delete mode 100644 upcoming-release-notes/2770.md

diff --git a/packages/loot-core/src/server/accounts/sync.test.ts b/packages/loot-core/src/server/accounts/sync.test.ts
index 13a9160a8..1ea00a4d0 100644
--- a/packages/loot-core/src/server/accounts/sync.test.ts
+++ b/packages/loot-core/src/server/accounts/sync.test.ts
@@ -342,108 +342,4 @@ describe('Account sync', () => {
       'bakkerij-renamed',
     ]);
   });
-
-  test('reconcile does not merge transactions with different ‘imported_id’ values', async () => {
-    const { id } = await prepareDatabase();
-
-    let payees = await getAllPayees();
-    expect(payees.length).toBe(0);
-
-    // Add first transaction
-    await reconcileTransactions(id, [
-      {
-        date: '2024-04-05',
-        amount: -1239,
-        imported_payee: 'Acme Inc.',
-        payee_name: 'Acme Inc.',
-        imported_id: 'b85cdd57-5a1c-4ca5-bd54-12e5b56fa02c',
-        notes: 'TEST TRANSACTION',
-        cleared: true,
-      },
-    ]);
-
-    payees = await getAllPayees();
-    expect(payees.length).toBe(1);
-
-    let transactions = await getAllTransactions();
-    expect(transactions.length).toBe(1);
-
-    // Add second transaction
-    await reconcileTransactions(id, [
-      {
-        date: '2024-04-06',
-        amount: -1239,
-        imported_payee: 'Acme Inc.',
-        payee_name: 'Acme Inc.',
-        imported_id: 'ca1589b2-7bc3-4587-a157-476170b383a7',
-        notes: 'TEST TRANSACTION',
-        cleared: true,
-      },
-    ]);
-
-    payees = await getAllPayees();
-    expect(payees.length).toBe(1);
-
-    transactions = await getAllTransactions();
-    expect(transactions.length).toBe(2);
-
-    expect(
-      transactions.find(
-        t => t.imported_id === 'b85cdd57-5a1c-4ca5-bd54-12e5b56fa02c',
-      ).amount,
-    ).toBe(-1239);
-    expect(
-      transactions.find(
-        t => t.imported_id === 'ca1589b2-7bc3-4587-a157-476170b383a7',
-      ).amount,
-    ).toBe(-1239);
-  });
-
-  test(
-    'given an imported tx with no imported_id, ' +
-      'when an existing transaction that has an imported_id and matches amount and is within 7 days of imported tx,' +
-      'then imported tx should reconcile with existing transaction from fuzzy match',
-    async () => {
-      const { id } = await prepareDatabase();
-
-      let payees = await getAllPayees();
-      expect(payees.length).toBe(0);
-
-      const existingTx = {
-        date: '2024-04-05',
-        amount: -1239,
-        imported_payee: 'Acme Inc.',
-        payee_name: 'Acme Inc.',
-        imported_id: 'b85cdd57-5a1c-4ca5-bd54-12e5b56fa02c',
-        notes: 'TEST TRANSACTION',
-        cleared: true,
-      };
-
-      // Add transaction to represent existing transaction with imoprted_id
-      await reconcileTransactions(id, [existingTx]);
-
-      payees = await getAllPayees();
-      expect(payees.length).toBe(1);
-
-      let transactions = await getAllTransactions();
-      expect(transactions.length).toBe(1);
-
-      // Import transaction similar to existing but with different date and no imported_id
-      await reconcileTransactions(id, [
-        {
-          ...existingTx,
-          date: '2024-04-06',
-          imported_id: null,
-        },
-      ]);
-
-      payees = await getAllPayees();
-      expect(payees.length).toBe(1);
-
-      transactions = await getAllTransactions();
-      expect(transactions.length).toBe(1);
-
-      expect(transactions[0].amount).toBe(-1239);
-    },
-  );
 });
diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.ts
index 034a21231..618c48918 100644
--- a/packages/loot-core/src/server/accounts/sync.ts
+++ b/packages/loot-core/src/server/accounts/sync.ts
@@ -400,15 +400,8 @@ export async function reconcileTransactions(
       // fields.
       fuzzyDataset = await db.all(
         `SELECT id, is_parent, date, imported_id, payee, category, notes, reconciled FROM v_transactions
-           WHERE
-             -- If both ids are set, and we didn't match earlier then skip dedup
-             ( imported_id IS NULL OR ? IS NULL )
-             -- Look 7 days ahead, 7 days behind
-             AND date >= ? AND date <= ? AND amount = ?
-             AND account = ?
-        `,
+           WHERE date >= ? AND date <= ? AND amount = ? AND account = ?`,
         [
-          trans.imported_id || null,
           db.toDateRepr(monthUtils.subDays(trans.date, 7)),
           db.toDateRepr(monthUtils.addDays(trans.date, 7)),
           trans.amount || 0,
diff --git a/upcoming-release-notes/2770.md b/upcoming-release-notes/2770.md
deleted file mode 100644
index 3681a1e52..000000000
--- a/upcoming-release-notes/2770.md
+++ /dev/null
@@ -1,6 +0,0 @@
----
-category: Bugfix
-authors: [ttlgeek, strazto, pmoon00]
----
-
-Prevent transaction deduplication for imported transactions
-- 
GitLab