mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 794028 - CSV import, default to matching full account name
If the account map doesn't yield a result, try to map the import string against existing accounts' full names
This commit is contained in:
parent
51706f289c
commit
1ce5ace25f
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user