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.
This commit is contained in:
Robert Fewell
2021-03-18 10:28:24 +00:00
parent d335a803e6
commit a7d383fc16

View File

@@ -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<const char*> col_types_str;
for (auto col_type : m_column_types)