Skip to content

Commit

Permalink
Fix bug - Manually entered split transactions are not cleared on import
Browse files Browse the repository at this point in the history
actualbudget#200 (actualbudget#1465)

* Added clear transactions on import option

* Added release note

* Added cleared column to csv export

* fixed Manually entered split transactions are not cleared on import

* Revert "Added cleared column to csv export"

This reverts commit 2952bc3.

* added release note

* Copied same code to Gocardless

* Updated var name

* Updated to only query  changed transactions instead of all
  • Loading branch information
kstockk authored Aug 23, 2023
1 parent 3e27b66 commit 2cfa1fe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
24 changes: 22 additions & 2 deletions packages/loot-core/src/server/accounts/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_transactions
WHERE date >= ? AND date <= ? AND amount = ? AND account = ? AND is_child = 0`,
[
db.toDateRepr(monthUtils.subDays(trans.date, 4)),
Expand Down Expand Up @@ -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 transaction
let finalTransaction = {
Expand Down Expand Up @@ -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_transactions
WHERE date >= ? AND date <= ? AND amount = ? AND account = ? AND is_child = 0`,
[
db.toDateRepr(monthUtils.subDays(trans.date, 4)),
Expand Down Expand Up @@ -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 transaction
let finalTransaction = {
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/1465.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [kstockk]
---

Fixed clearing split transactions when importing matched transactions

0 comments on commit 2cfa1fe

Please sign in to comment.