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

Fix bug - Manually entered split transactions are not cleared on import #200 #1465

Merged
merged 17 commits into from
Aug 23, 2023

Conversation

kstockk
Copy link
Contributor

@kstockk kstockk commented Aug 5, 2023

Relates to #200

@netlify
Copy link

netlify bot commented Aug 5, 2023

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 4ff0984
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/64e5bba06714140008f14906
😎 Deploy Preview https://deploy-preview-1465.demo.actualbudget.org/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2023

Bundle Stats — desktop-client

Hey 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

Files count Total bundle size % Changed
14 2.13 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/main.js 967.47 kB 0%
static/js/171.chunk.js 396.24 kB 0%
static/media/Inter-italic.var.woff2 239.29 kB 0%
static/media/Inter-roman.var.woff2 221.86 kB 0%
static/js/wide-components.chunk.js 137.22 kB 0%
static/js/383.chunk.js 117.35 kB 0%
static/js/reports.chunk.js 40.59 kB 0%
static/js/narrow-components.chunk.js 25.19 kB 0%
static/js/969.chunk.js 12.94 kB 0%
static/js/resize-observer-polyfill.chunk.js 8.12 kB 0%
static/css/main.css 5.82 kB 0%
asset-manifest.json 1.78 kB 0%
index.html 1.66 kB 0%
static/media/browser-server.js 963 B 0%

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2023

Bundle Stats — loot-core

Hey 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

Files count Total bundle size % Changed
2 1.97 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1013.48 kB 0%
xfo.xfo.kcab.worker.js 1004.04 kB 0%

@kstockk kstockk marked this pull request as ready for review August 5, 2023 12:26
@kstockk kstockk closed this Aug 6, 2023
@kstockk kstockk reopened this Aug 6, 2023
@shall0pass
Copy link
Contributor

What is the best way to test this?

@kyrias
Copy link
Contributor

kyrias commented Aug 22, 2023

  • Link an account to the GoCardless DEMO bank.
  • Select one of the imported transactions and create one with the same duplicates, but make it a split transaction.
  • Delete the original.
  • Sync again. Transaction is marked as cleared but the cleared total does not reflect this transaction.

Comment on lines 540 to 553
// 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 });

Copy link
Contributor

@kyrias kyrias Aug 22, 2023

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 = {

Copy link
Contributor Author

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

@kstockk
Copy link
Contributor Author

kstockk commented Aug 23, 2023

To test without GoCardless.

Export Account's csv.
Import the csv back into the account -> This should mark all transactions as cleared
Undo to mark them as uncleared
Edit some transactions by making them split transactions
Import the csv back into the account -> this should mark all transactions as cleared (including the split transactions)

Copy link
Contributor

@shall0pass shall0pass left a 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!

@shall0pass shall0pass merged commit 240dc46 into actualbudget:master Aug 23, 2023
15 checks passed
@trafico-bot trafico-bot bot added ✨ Merged Pull Request has been merged successfully and removed ✅ Approved labels Aug 23, 2023
FlorianLang06 pushed a commit to FlorianLang06/actual that referenced this pull request Mar 7, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Merged Pull Request has been merged successfully
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants