Fix issue with failure to run reconciliation with all accounts present

in a multi-account OFX file.
Do that by saving a GList of statements, rather than a pointer to a single one.
Also freeing of info happens during the call to process_next_file.
This commit is contained in:
jean 2021-10-18 09:08:33 -07:00
parent b95df85121
commit 1e80810e4e

View File

@ -74,7 +74,7 @@ typedef struct _ofx_info
Account *last_investment_account;
Account *last_income_account;
gint num_trans_processed; // Number of transactions processed
struct OfxStatementData* statement; // Statement, if any
GList* statement; // Statement, if any
gboolean run_reconcile; // If TRUE the reconcile window is opened after matching.
GSList* file_list; // List of OFX files to import
GList* trans_list; // We store the processed ofx transactions here
@ -938,8 +938,9 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void *user_data)
int ofx_proc_statement_cb (struct OfxStatementData data, void * statement_user_data)
{
ofx_info* info = (ofx_info*) statement_user_data;
info->statement = g_new (struct OfxStatementData, 1);
*info->statement = data;
struct OfxStatementData *statement = g_new (struct OfxStatementData, 1);
*statement = data;
info->statement = g_list_prepend (info->statement, statement);
return 0;
}
@ -1101,7 +1102,7 @@ gnc_ofx_process_next_file (GtkDialog *dialog, gpointer user_data)
{
ofx_info* info = (ofx_info*) user_data;
// Free the statement (if it was allocated)
g_free (info->statement);
g_list_free_full (info->statement, g_free);
info->statement = NULL;
// Done with the previous OFX file, process the next one if any.
@ -1132,10 +1133,7 @@ gnc_ofx_match_done (GtkDialog *dialog, gpointer user_data)
* transaction, don't go to the next of xfile.
*/
if (info->response != GTK_RESPONSE_OK)
{
g_free (info);
return;
}
if (info->trans_list)
{
@ -1148,27 +1146,49 @@ gnc_ofx_match_done (GtkDialog *dialog, gpointer user_data)
return;
}
if (info->run_reconcile && info->statement)
if (info->run_reconcile && info->statement && info->statement->data)
{
struct OfxStatementData* statement = info->statement->data;
// Open a reconcile window.
Account* account = gnc_import_select_account (gnc_gen_trans_list_widget(info->gnc_ofx_importer_gui),
info->statement->account_id,
statement->account_id,
0, NULL, NULL, ACCT_TYPE_NONE, NULL, NULL);
if (account && info->statement->ledger_balance_valid)
if (account && statement->ledger_balance_valid)
{
gnc_numeric value = double_to_gnc_numeric (info->statement->ledger_balance,
gnc_numeric value = double_to_gnc_numeric (statement->ledger_balance,
xaccAccountGetCommoditySCU (account),
GNC_HOW_RND_ROUND_HALF_UP);
RecnWindow* rec_window = recnWindowWithBalance (GTK_WIDGET (info->parent), account, value,
info->statement->ledger_balance_date);
statement->ledger_balance_date);
// Connect to destroy, at which point we'll process the next OFX file..
g_signal_connect (G_OBJECT (gnc_ui_reconcile_window_get_window (rec_window)), "destroy",
G_CALLBACK (gnc_ofx_process_next_file), info);
G_CALLBACK (gnc_ofx_match_done), info);
if (info->statement->next)
info->statement = info->statement->next;
else
{
g_list_free_full (g_list_first (info->statement), g_free);
info->statement = NULL;
}
return;
}
}
else
{
if (info->statement && info->statement->next)
{
info->statement = info->statement->next;
gnc_ofx_match_done (dialog, user_data);
return;
}
else
{
g_list_free_full (g_list_first (info->statement), g_free);
info->statement = NULL;
}
}
gnc_ofx_process_next_file (NULL, info);
}
@ -1217,18 +1237,21 @@ runMatcher (ofx_info* info, char * selected_filename, gboolean go_to_next_file)
Account* _account = g_hash_table_lookup (trans_hash, date_amount_key);
if (_account && _account != account)
{
// There is a transaction with identical amounts and
// dates, but a different account. That's a potential
// transfer so process this transaction in a later call.
gchar *name1 = gnc_account_get_full_name (account);
gchar *name2 = gnc_account_get_full_name (_account);
gchar *amtstr = gnc_numeric_to_string (xaccSplitGetAmount (split));
gchar *datestr = qof_print_date (xaccTransGetDate (trans));
DEBUG ("Potential transfer %s %s %s %s\n", name1, name2, amtstr, datestr);
g_free (name1);
g_free (name2);
g_free (amtstr);
g_free (datestr);
if (qof_log_check (G_LOG_DOMAIN, QOF_LOG_DEBUG))
{
// There is a transaction with identical amounts and
// dates, but a different account. That's a potential
// transfer so process this transaction in a later call.
gchar *name1 = gnc_account_get_full_name (account);
gchar *name2 = gnc_account_get_full_name (_account);
gchar *amtstr = gnc_numeric_to_string (xaccSplitGetAmount (split));
gchar *datestr = qof_print_date (xaccTransGetDate (trans));
DEBUG ("Potential transfer %s %s %s %s\n", name1, name2, amtstr, datestr);
g_free (name1);
g_free (name2);
g_free (amtstr);
g_free (datestr);
}
trans_list_remain = g_list_prepend (trans_list_remain, trans);
g_free (date_amount_key);
}
@ -1254,7 +1277,7 @@ runMatcher (ofx_info* info, char * selected_filename, gboolean go_to_next_file)
selected_filename, info->num_trans_processed);
// This is required to ensure we don't mistakenly assume the user canceled.
info->response = GTK_RESPONSE_OK;
gnc_ofx_match_done (NULL,info);
gnc_ofx_match_done (NULL, info);
return;
}
}