gnucash stable: [import-main-matcher.c] defer account balances until import complete

Christopher Lam clam at code.gnucash.org
Sat Apr 22 09:32:27 EDT 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/2b4f0b3b (commit)
	from  https://github.com/Gnucash/gnucash/commit/80762ef8 (commit)



commit 2b4f0b3b8c4b6c7e75886968e696a46b3bfc73b2
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Apr 22 21:11:05 2023 +0800

     [import-main-matcher.c] defer account balances until import complete

diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c
index 99047aaef0..ef306740a7 100644
--- a/gnucash/import-export/import-main-matcher.c
+++ b/gnucash/import-export/import-main-matcher.c
@@ -514,6 +514,15 @@ gnc_gen_trans_list_show_all (GNCImportMainMatcher *info)
     gnc_gen_trans_list_show_accounts_column (info);
 }
 
+static void acc_begin_edit (GList **accounts_modified, Account *acc)
+{
+    if (!acc || !accounts_modified || g_list_find (*accounts_modified, acc))
+        return;
+
+    DEBUG ("xaccAccountBeginEdit for acc %s", xaccAccountGetName (acc));
+    xaccAccountBeginEdit (acc);
+    *accounts_modified = g_list_prepend (*accounts_modified, acc);
+}
 void
 on_matcher_ok_clicked (GtkButton *button, GNCImportMainMatcher *info)
 {
@@ -535,6 +544,7 @@ on_matcher_ok_clicked (GtkButton *button, GNCImportMainMatcher *info)
     gnc_suspend_gui_refresh ();
     bool first_tran = true;
     bool append_text = gtk_toggle_button_get_active ((GtkToggleButton*) info->append_text);
+    GList *accounts_modified = NULL;
     do
     {
         GNCImportTransInfo *trans_info;
@@ -542,6 +552,12 @@ on_matcher_ok_clicked (GtkButton *button, GNCImportMainMatcher *info)
                             DOWNLOADED_COL_DATA, &trans_info,
                             -1);
 
+        Split* first_split = gnc_import_TransInfo_get_fsplit (trans_info);
+        Transaction *trans = xaccSplitGetParent (first_split);
+
+        for (GList *n = xaccTransGetSplitList (trans); n; n = g_list_next (n))
+            acc_begin_edit (&accounts_modified, xaccSplitGetAccount (n->data));
+
         // Allow the backend to know if the Append checkbox is ticked or unticked
         // by propagating info->append_text to every trans_info->append_text
         gnc_import_TransInfo_set_append_text( trans_info, append_text);
@@ -552,12 +568,12 @@ on_matcher_ok_clicked (GtkButton *button, GNCImportMainMatcher *info)
         // Get the import account from the first split.
         if (first_tran)
         {
-            Split* first_split = gnc_import_TransInfo_get_fsplit (trans_info);
             xaccAccountSetAppendText (xaccSplitGetAccount(first_split), append_text);
             first_tran = false;
         }
-        // Note: if there's only 1 split (unbalanced) one will be created with the unbalanced account,
-        // and for that account the defer balance will not be set. So things will be slow.
+
+        Account *dest_acc = gnc_import_TransInfo_get_destacc (trans_info);
+        acc_begin_edit (&accounts_modified, dest_acc);
 
         if (gnc_import_process_trans_item (NULL, trans_info))
         {
@@ -576,6 +592,7 @@ on_matcher_ok_clicked (GtkButton *button, GNCImportMainMatcher *info)
     gnc_resume_gui_refresh ();
 
     /* DEBUG ("End") */
+    g_list_free_full (accounts_modified, (GDestroyNotify)xaccAccountCommitEdit);
 }
 
 void



Summary of changes:
 gnucash/import-export/import-main-matcher.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)



More information about the gnucash-changes mailing list