From a7d383fc16002ac456b00ca72f79cac98816a1ba Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Thu, 18 Mar 2021 10:28:24 +0000 Subject: [PATCH] Bug 798149 - Account name change affects CSV saved import setting The account full path was being used in the CSV saved settings so if any account name is change in the path it would prevent recall of the base account used. To fix this the account guid is saved instead and when recalled the account is looked up first by guid, if this fails the full path is checked which if successful immediately updates the saved base account setting with the account guid for future use. --- .../csv-imp/gnc-imp-settings-csv-tx.cpp | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/gnucash/import-export/csv-imp/gnc-imp-settings-csv-tx.cpp b/gnucash/import-export/csv-imp/gnc-imp-settings-csv-tx.cpp index eda119ab1b..8ba7995aae 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-settings-csv-tx.cpp +++ b/gnucash/import-export/csv-imp/gnc-imp-settings-csv-tx.cpp @@ -172,7 +172,25 @@ CsvTransImpSettings::load (void) gchar *key_char = g_key_file_get_string (keyfile, group.c_str(), CSV_ACCOUNT, &key_error); if (key_char && *key_char != '\0') - m_base_account = gnc_account_lookup_by_full_name (gnc_get_current_root_account(), key_char); + { + QofBook* book = gnc_get_current_book (); + GncGUID guid; + + if (string_to_guid (key_char, &guid)) // find account by guid + m_base_account = xaccAccountLookup (&guid, book); + + if (m_base_account == nullptr) + { + m_base_account = gnc_account_lookup_by_full_name (gnc_get_current_root_account(), key_char); + + if (m_base_account) // save the account as guid, introduced in version 4.5 + { + gchar acct_guid[GUID_ENCODING_LENGTH + 1]; + guid_to_string_buff (xaccAccountGetGUID (m_base_account), acct_guid); + g_key_file_set_string (keyfile, group.c_str(), CSV_ACCOUNT, acct_guid); + } + } + } m_load_error |= handle_load_error (&key_error, group); if (key_char) g_free (key_char); @@ -241,7 +259,11 @@ CsvTransImpSettings::save (void) g_key_file_set_boolean (keyfile, group.c_str(), CSV_MULTI_SPLIT, m_multi_split); if (m_base_account) - g_key_file_set_string (keyfile, group.c_str(), CSV_ACCOUNT, gnc_account_get_full_name(m_base_account)); + { + gchar acct_guid[GUID_ENCODING_LENGTH + 1]; + guid_to_string_buff (xaccAccountGetGUID (m_base_account), acct_guid); + g_key_file_set_string (keyfile, group.c_str(), CSV_ACCOUNT, acct_guid); + } std::vector col_types_str; for (auto col_type : m_column_types)