Skip to content

Commit

Permalink
🐛 (import) patch phantom transactions getting created (#2464)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatissJanis authored Mar 21, 2024
1 parent d763575 commit 5343030
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/loot-core/src/server/accounts/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,26 @@ export async function reconcileExternalTransactions(acctId, transactions) {
acctId,
],
);

// Sort the matched transactions according to the distance from the original
// transactions date. i.e. if the original transaction is in 21-02-2024 and
// the matched transactions are: 20-02-2024, 21-02-2024, 29-02-2024 then
// the resulting data-set should be: 21-02-2024, 20-02-2024, 29-02-2024.
fuzzyDataset = fuzzyDataset.sort((a, b) => {
const aDistance = Math.abs(
dateFns.differenceInMilliseconds(
dateFns.parseISO(trans.date),
dateFns.parseISO(db.fromDateRepr(a.date)),
),
);
const bDistance = Math.abs(
dateFns.differenceInMilliseconds(
dateFns.parseISO(trans.date),
dateFns.parseISO(db.fromDateRepr(b.date)),
),
);
return aDistance > bDistance ? 1 : -1;
});
}

transactionsStep1.push({
Expand Down Expand Up @@ -645,6 +665,26 @@ export async function reconcileTransactions(acctId, transactions) {
acctId,
],
);

// Sort the matched transactions according to the distance from the original
// transactions date. i.e. if the original transaction is in 21-02-2024 and
// the matched transactions are: 20-02-2024, 21-02-2024, 29-02-2024 then
// the resulting data-set should be: 21-02-2024, 20-02-2024, 29-02-2024.
fuzzyDataset = fuzzyDataset.sort((a, b) => {
const aDistance = Math.abs(
dateFns.differenceInMilliseconds(
dateFns.parseISO(trans.date),
dateFns.parseISO(db.fromDateRepr(a.date)),
),
);
const bDistance = Math.abs(
dateFns.differenceInMilliseconds(
dateFns.parseISO(trans.date),
dateFns.parseISO(db.fromDateRepr(b.date)),
),
);
return aDistance > bDistance ? 1 : -1;
});
}

transactionsStep1.push({
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2464.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [MatissJanis]
---

Fix csv/ofx import sometimes importing duplicate transactions

0 comments on commit 5343030

Please sign in to comment.