-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix bug - Manually entered split transactions are not cleared on import #200 #1465
Conversation
This reverts commit 2952bc3.
✅ Deploy Preview for actualbudget ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Bundle Stats — desktop-clientHey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
Changeset No files were changed View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger No assets were bigger Smaller No assets were smaller Unchanged
|
Bundle Stats — loot-coreHey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
Changeset No files were changed View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger No assets were bigger Smaller No assets were smaller Unchanged
|
What is the best way to test this? |
|
// Make sure the "cleared" flag is synced up with the parent | ||
// transactions | ||
let clearedRows = await db.all(` | ||
SELECT t.id, p.cleared FROM v_transactions t | ||
LEFT JOIN v_transactions p ON t.parent_id = p.id | ||
WHERE t.is_child = 1 AND t.cleared != p.cleared | ||
`); | ||
|
||
let updatedClearedRows = clearedRows.map(row => ({ | ||
id: row.id, | ||
cleared: row.cleared === 1, | ||
})); | ||
await batchUpdateTransactions({ updated: updatedClearedRows }); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having to query every transaction like this seems very inefficient. I think the following would be a better solution:
diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.ts
index 4733dc6f..4cbea6d5 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_transactions
WHERE date >= ? AND date <= ? AND amount = ? AND account = ? AND is_child = 0`,
[
db.toDateRepr(monthUtils.subDays(trans.date, 4)),
@@ -509,6 +509,17 @@ 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 = {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Thanks for for the suggestion
I've updated it in both the reconcileGoCardlessTransactions and reconcileTransactions functions
Please review
To test without GoCardless. Export Account's csv. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
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
Relates to #200