Initially select the last account chosen in the account picker dialogs.

Separately keeps track of last investment account, security account,
and income account.  One issue is that gnc_import_select_account
doesn't tell the caller if it put up a dialog or found the online ID
on an existing account.  This means the last account may be one the
user didn't manually select.  This may or may not be the right thing
to do.
This commit is contained in:
Mike Alexander
2020-01-09 02:03:08 -05:00
parent a4e35f3cea
commit 0a4347bd5e

View File

@@ -71,6 +71,9 @@ typedef struct _ofx_info
GSList* statement; GSList* statement;
GtkWindow* parent; GtkWindow* parent;
GNCImportMainMatcher *gnc_ofx_importer_gui; GNCImportMainMatcher *gnc_ofx_importer_gui;
Account *last_import_account;
Account *last_investment_account;
Account *last_income_account;
GList *created_commodites ; GList *created_commodites ;
} ofx_info ; } ofx_info ;
@@ -434,12 +437,13 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void *user_data)
account = gnc_import_select_account(gnc_gen_trans_list_widget(info->gnc_ofx_importer_gui), account = gnc_import_select_account(gnc_gen_trans_list_widget(info->gnc_ofx_importer_gui),
data.account_id, data.account_id,
0, NULL, NULL, ACCT_TYPE_NONE, 0, NULL, NULL, ACCT_TYPE_NONE,
NULL, NULL); info->last_import_account, NULL);
if (account == NULL) if (account == NULL)
{ {
PERR("Unable to find account for id %s", data.account_id); PERR("Unable to find account for id %s", data.account_id);
return 0; return 0;
} }
info->last_import_account = account;
/***** Validate the input strings to ensure utf8 *****/ /***** Validate the input strings to ensure utf8 *****/
if (data.name_valid) if (data.name_valid)
gnc_utf8_strip_invalid(data.name); gnc_utf8_strip_invalid(data.name);
@@ -652,8 +656,10 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void *user_data)
investment_account_text, investment_account_text,
investment_commodity, investment_commodity,
ACCT_TYPE_STOCK, ACCT_TYPE_STOCK,
NULL, info->last_investment_account,
NULL); NULL);
if (investment_account)
info->last_investment_account = investment_account;
// but use it only if that's really the right commodity // but use it only if that's really the right commodity
if (investment_account if (investment_account
@@ -681,8 +687,10 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void *user_data)
investment_account_text, investment_account_text,
investment_commodity, investment_commodity,
ACCT_TYPE_STOCK, ACCT_TYPE_STOCK,
NULL, info->last_investment_account,
&choosing_account); &choosing_account);
if (investment_account)
info->last_investment_account = investment_account;
} }
// Does the chosen account have the right commodity? // Does the chosen account have the right commodity?
if (investment_account && xaccAccountGetCommodity(investment_account) != investment_commodity) if (investment_account && xaccAccountGetCommodity(investment_account) != investment_commodity)
@@ -817,10 +825,11 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void *user_data)
investment_account_text, investment_account_text,
currency, currency,
ACCT_TYPE_INCOME, ACCT_TYPE_INCOME,
NULL, info->last_income_account,
NULL); NULL);
if (income_account != NULL) if (income_account != NULL)
{ {
info->last_income_account = income_account;
set_associated_income_account(investment_account, set_associated_income_account(investment_account,
income_account); income_account);
DEBUG("KVP written"); DEBUG("KVP written");
@@ -1005,7 +1014,11 @@ int ofx_proc_account_cb(struct OfxAccountData data, void * account_user_data)
account = gnc_import_select_account (GTK_WIDGET(info->parent), account = gnc_import_select_account (GTK_WIDGET(info->parent),
data.account_id, 1, data.account_id, 1,
account_description, default_commodity, account_description, default_commodity,
default_type, NULL, NULL); default_type, info->last_import_account, NULL);
if (account)
{
info->last_import_account = account;
}
g_free(account_description); g_free(account_description);
} }
else else
@@ -1053,7 +1066,7 @@ void gnc_file_ofx_import (GtkWindow *parent)
GtkFileFilter* filter = gtk_file_filter_new (); GtkFileFilter* filter = gtk_file_filter_new ();
GSList *iter = NULL; GSList *iter = NULL;
// Create the structure we're using to gather reconciliation information. // Create the structure we're using to gather reconciliation information.
ofx_info info = {0, NULL, parent, NULL, NULL}; ofx_info info = {0, NULL, parent, NULL, NULL, NULL, NULL, NULL};
ofx_PARSER_msg = false; ofx_PARSER_msg = false;
ofx_DEBUG_msg = false; ofx_DEBUG_msg = false;