diff --git a/src/import-export/import-account-matcher.c b/src/import-export/import-account-matcher.c index 2647bd563e..b5c565cebf 100644 --- a/src/import-export/import-account-matcher.c +++ b/src/import-export/import-account-matcher.c @@ -170,7 +170,7 @@ Account * gnc_import_select_account(GtkWidget *parent, picker->new_account_default_commodity = new_account_default_commodity; picker->new_account_default_type = new_account_default_type; - /*DEBUG("Looking for account with online_id: %s", account_online_id_value);*/ + /*DEBUG("Looking for account with online_id: \"%s\"", account_online_id_value);*/ if (account_online_id_value != NULL) { retval = @@ -179,6 +179,34 @@ Account * gnc_import_select_account(GtkWidget *parent, /* This argument will only be used as a "const char*" */ (void*)account_online_id_value); + + /* BEGIN: try again without extra space at the end */ + /* + * libofx, used for file import, generates online_id as + * ACCTID + space + ACCTKEY which differs from the online_id + * generated by aqbanking for online ofx transfer as ACCTID. + * + * If a gnucash account has been associated with an online_id + * via aqbanking data, it is not possible to construct an OFX + * file for gnucash import that matches the same online_id + * because even with no ACCTKEY in the file, there will be a + * trailing space. + * + * This is a hack to overcome that problem. + */ + if ((retval == NULL) && g_str_has_suffix(account_online_id_value, " ")) + { + gchar *trimmed = g_strndup(account_online_id_value, strlen(account_online_id_value) - 1); + if (trimmed) + { + retval = gnc_account_foreach_descendant_until( + gnc_get_current_root_account (), + test_acct_online_id_match, + (void *)trimmed); + } + g_free(trimmed); + } + /* END: try again without extra space at the end */ } if (retval == NULL && auto_create != 0) {