A local-first personal finance app
Fix bug - Manually entered split transactions are not cleared on import #200 (#1465)
Khanh Nguyen240dc46a23de
diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.tsindex 4733dc6fa8..ae80d77516 100644--- a/packages/loot-core/src/server/accounts/sync.ts+++ b/packages/loot-core/src/server/accounts/sync.ts@@ -431,7 +431,7 @@ export async function reconcileGoCardlessTransactions(acctId, transactions) {// matched transaction. See the final pass below for the needed// fields.fuzzyDataset = await db.all(- `SELECT id, date, imported_id, payee, category, notes FROM v_transactions+ `SELECT id, is_parent, date, imported_id, payee, category, notes FROM v_transactionsWHERE date >= ? AND date <= ? AND amount = ? AND account = ? AND is_child = 0`,[db.toDateRepr(monthUtils.subDays(trans.date, 4)),@@ -509,6 +509,16 @@ export async function reconcileGoCardlessTransactions(acctId, transactions) {if (hasFieldsChanged(existing, updates, Object.keys(updates))) {updated.push({ id: existing.id, ...updates });}++ if (existing.is_parent && existing.cleared !== updates.cleared) {+ const children = await db.all(+ 'SELECT id FROM v_transactions WHERE parent_id = ?',+ [existing.id],+ );+ for (const child of children) {+ updated.push({ id: child.id, cleared: updates.cleared });+ }+ }} else {// Insert a new transactionlet finalTransaction = {@@ -575,7 +585,7 @@ export async function reconcileTransactions(acctId, transactions) {// matched transaction. See the final pass below for the needed// fields.fuzzyDataset = await db.all(- `SELECT id, date, imported_id, payee, category, notes FROM v_transactions+ `SELECT id, is_parent, date, imported_id, payee, category, notes FROM v_transactionsWHERE date >= ? AND date <= ? AND amount = ? AND account = ? AND is_child = 0`,[db.toDateRepr(monthUtils.subDays(trans.date, 4)),@@ -654,6 +664,16 @@ export async function reconcileTransactions(acctId, transactions) {if (hasFieldsChanged(existing, updates, Object.keys(updates))) {updated.push({ id: existing.id, ...updates });}++ if (existing.is_parent && existing.cleared !== updates.cleared) {+ const children = await db.all(+ 'SELECT id FROM v_transactions WHERE parent_id = ?',+ [existing.id],+ );+ for (const child of children) {+ updated.push({ id: child.id, cleared: updates.cleared });+ }+ }} else {// Insert a new transactionlet finalTransaction = {diff --git a/upcoming-release-notes/1465.md b/upcoming-release-notes/1465.mdnew file mode 100644index 0000000000..aa654cb29d--- /dev/null+++ b/upcoming-release-notes/1465.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [kstockk]+---++Fixed clearing split transactions when importing matched transactions