Skip to content

Commit

Permalink
Bug 794028 - CSV import, default to matching full account name
Browse files Browse the repository at this point in the history
If the account map doesn't yield a result, try to map
the import string against existing accounts' full names
  • Loading branch information
gjanssens committed Feb 4, 2023
1 parent 51706f2 commit 1ce5ace
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
24 changes: 11 additions & 13 deletions gnucash/import-export/csv-imp/gnc-csv-account-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,19 @@ gnc_csv_account_map_load_mappings (GtkTreeModel *mappings_store)
// Walk through the list, reading each row
gtk_tree_model_get (GTK_TREE_MODEL(mappings_store), &iter, MAPPING_STRING, &map_string, MAPPING_ACCOUNT, &account, -1);

if (account == NULL) // if account is NULL, store has not been updated
// Look for an account matching the map_string
// It may already be set in the tree model. If not we try to match the map_string with
// - an entry in our saved account maps
// - a full name of any of our existing accounts
if (account ||
(account = gnc_csv_account_map_search (map_string)) ||
(account = gnc_account_lookup_by_full_name (gnc_get_current_root_account(), map_string)))
{
account = gnc_csv_account_map_search (map_string); //search the account list for the map_string

if (account == NULL) // account still NULL, we have no map
{
g_free (map_string);
valid = gtk_tree_model_iter_next (mappings_store, &iter);
continue;
}
fullpath = gnc_account_get_full_name (account);
gtk_list_store_set (GTK_LIST_STORE(mappings_store), &iter, MAPPING_FULLPATH, fullpath, -1);
gtk_list_store_set (GTK_LIST_STORE(mappings_store), &iter, MAPPING_ACCOUNT, account, -1);
g_free (fullpath);
}
fullpath = gnc_account_get_full_name (account);
gtk_list_store_set (GTK_LIST_STORE(mappings_store), &iter, MAPPING_FULLPATH, fullpath, -1);
gtk_list_store_set (GTK_LIST_STORE(mappings_store), &iter, MAPPING_ACCOUNT, account, -1);
g_free (fullpath);

g_free (map_string);
valid = gtk_tree_model_iter_next (mappings_store, &iter);
Expand Down
9 changes: 9 additions & 0 deletions gnucash/import-export/csv-imp/gnc-csv-account-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ extern "C" {
enum GncImportColumn {MAPPING_STRING, MAPPING_FULLPATH, MAPPING_ACCOUNT};

/** Load the import mappings.
*
* For each mapping string in the tree model, try to find a
* corresponding account and account full path.
*
* - if the account was already set, just update the full path
* - if the mapping string matches an account in the account maps,
* use that account and its corresponding full name
* - otherwise search for an existing account whose full name matches the
* mapping string
*
*/
void gnc_csv_account_map_load_mappings (GtkTreeModel *mappings_store);
Expand Down
8 changes: 4 additions & 4 deletions gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ void GncPreSplit::set (GncTransPropType prop_type, const std::string& value)
m_account = boost::none;
if (value.empty())
throw std::invalid_argument (_("Account value can't be empty."));
acct = gnc_csv_account_map_search (value.c_str());
if (acct)
if ((acct = gnc_csv_account_map_search (value.c_str())) ||
(acct = gnc_account_lookup_by_full_name (gnc_get_current_root_account(), value.c_str())))
m_account = acct;
else
throw std::invalid_argument (_(bad_acct));
Expand All @@ -439,8 +439,8 @@ void GncPreSplit::set (GncTransPropType prop_type, const std::string& value)
if (value.empty())
throw std::invalid_argument (_("Transfer account value can't be empty."));

acct = gnc_csv_account_map_search (value.c_str());
if (acct)
if ((acct = gnc_csv_account_map_search (value.c_str())) ||
(acct = gnc_account_lookup_by_full_name (gnc_get_current_root_account(), value.c_str())))
m_taccount = acct;
else
throw std::invalid_argument (_(bad_tacct));
Expand Down

0 comments on commit 1ce5ace

Please sign in to comment.