From d37622162af016373418d881815e8e39fe03a96d Mon Sep 17 00:00:00 2001
From: yoyotogblo <31814048+yoyotogblo@users.noreply.github.com>
Date: Sat, 3 Feb 2024 13:08:45 -0500
Subject: [PATCH] Change lookback and look forward time range when fuzzy
 matching (#2300)

Change to 7 days prior and after for imported transactions when fuzzy matching
---
 packages/loot-core/src/server/accounts/sync.ts | 12 ++++++------
 upcoming-release-notes/2300.md                 |  6 ++++++
 2 files changed, 12 insertions(+), 6 deletions(-)
 create mode 100644 upcoming-release-notes/2300.md

diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.ts
index c394f7f8c..ccf2d09ab 100644
--- a/packages/loot-core/src/server/accounts/sync.ts
+++ b/packages/loot-core/src/server/accounts/sync.ts
@@ -468,7 +468,7 @@ export async function reconcileExternalTransactions(acctId, transactions) {
 
     // If it didn't match, query data needed for fuzzy matching
     if (!match) {
-      // Look 1 day ahead and 4 days back when fuzzy matching. This
+      // Look 7 days ahead and 7 days back when fuzzy matching. This
       // needs to select all fields that need to be read from the
       // matched transaction. See the final pass below for the needed
       // fields.
@@ -476,8 +476,8 @@ export async function reconcileExternalTransactions(acctId, transactions) {
         `SELECT id, is_parent, date, imported_id, payee, category, notes, reconciled FROM v_transactions
            WHERE date >= ? AND date <= ? AND amount = ? AND account = ?`,
         [
-          db.toDateRepr(monthUtils.subDays(trans.date, 4)),
-          db.toDateRepr(monthUtils.addDays(trans.date, 1)),
+          db.toDateRepr(monthUtils.subDays(trans.date, 7)),
+          db.toDateRepr(monthUtils.addDays(trans.date, 7)),
           trans.amount || 0,
           acctId,
         ],
@@ -631,7 +631,7 @@ export async function reconcileTransactions(acctId, transactions) {
 
     // If it didn't match, query data needed for fuzzy matching
     if (!match) {
-      // Look 1 day ahead and 4 days back when fuzzy matching. This
+      // Look 7 days ahead and 7 days back when fuzzy matching. This
       // needs to select all fields that need to be read from the
       // matched transaction. See the final pass below for the needed
       // fields.
@@ -639,8 +639,8 @@ export async function reconcileTransactions(acctId, transactions) {
         `SELECT id, is_parent, date, imported_id, payee, category, notes, reconciled FROM v_transactions
            WHERE date >= ? AND date <= ? AND amount = ? AND account = ?`,
         [
-          db.toDateRepr(monthUtils.subDays(trans.date, 4)),
-          db.toDateRepr(monthUtils.addDays(trans.date, 1)),
+          db.toDateRepr(monthUtils.subDays(trans.date, 7)),
+          db.toDateRepr(monthUtils.addDays(trans.date, 7)),
           trans.amount || 0,
           acctId,
         ],
diff --git a/upcoming-release-notes/2300.md b/upcoming-release-notes/2300.md
new file mode 100644
index 000000000..95017eaf1
--- /dev/null
+++ b/upcoming-release-notes/2300.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [yoyotogblo]
+---
+
+Change lookback and look forward time range when fuzzy matching
-- 
GitLab