Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider child transactions when fuzzy matching imported transactions #2309

Merged
merged 2 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/loot-core/src/server/accounts/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ async function normalizeTransactions(
return { normalized, payeesToCreate };
}

async function normalizeGoCardlessTransactions(transactions, acctId) {
async function normalizeExternalTransactions(transactions, acctId) {
const payeesToCreate = new Map();

const normalized = [];
Expand Down Expand Up @@ -429,12 +429,12 @@ async function createNewPayees(payeesToCreate, addsAndUpdates) {
});
}

export async function reconcileGoCardlessTransactions(acctId, transactions) {
export async function reconcileExternalTransactions(acctId, transactions) {
const hasMatched = new Set();
const updated = [];
const added = [];

const { normalized, payeesToCreate } = await normalizeGoCardlessTransactions(
const { normalized, payeesToCreate } = await normalizeExternalTransactions(
transactions,
acctId,
);
Expand Down Expand Up @@ -474,7 +474,7 @@ export async function reconcileGoCardlessTransactions(acctId, transactions) {
// fields.
fuzzyDataset = await db.all(
`SELECT id, is_parent, date, imported_id, payee, category, notes, reconciled FROM v_transactions
WHERE date >= ? AND date <= ? AND amount = ? AND account = ? AND is_child = 0`,
WHERE date >= ? AND date <= ? AND amount = ? AND account = ?`,
[
db.toDateRepr(monthUtils.subDays(trans.date, 4)),
db.toDateRepr(monthUtils.addDays(trans.date, 1)),
Expand Down Expand Up @@ -637,7 +637,7 @@ export async function reconcileTransactions(acctId, transactions) {
// fields.
fuzzyDataset = await db.all(
`SELECT id, is_parent, date, imported_id, payee, category, notes, reconciled FROM v_transactions
WHERE date >= ? AND date <= ? AND amount = ? AND account = ? AND is_child = 0`,
WHERE date >= ? AND date <= ? AND amount = ? AND account = ?`,
[
db.toDateRepr(monthUtils.subDays(trans.date, 4)),
db.toDateRepr(monthUtils.addDays(trans.date, 1)),
Expand Down Expand Up @@ -866,7 +866,7 @@ export async function syncExternalAccount(userId, userKey, id, acctId, bankId) {
}));

return runMutator(async () => {
const result = await reconcileGoCardlessTransactions(id, transactions);
const result = await reconcileExternalTransactions(id, transactions);
await updateAccountBalance(id, accountBalance);
return result;
});
Expand Down Expand Up @@ -922,7 +922,7 @@ export async function syncExternalAccount(userId, userKey, id, acctId, bankId) {
starting_balance_flag: true,
});

const result = await reconcileGoCardlessTransactions(id, transactions);
const result = await reconcileExternalTransactions(id, transactions);
return {
...result,
added: [initialId, ...result.added],
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2309.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [joel-jeremy]
---

Consider child transactions when fuzzy matching imported transactions.
Loading