From 087501d316f9627748560210a95a66841849a9c4 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sun, 14 Aug 2022 15:31:46 -0700 Subject: [PATCH] Bug 798262 - Scheduled transactions with blank amounts do not get created. Handle template transactions that don't have any splits with empty credit and debit strings and those having no set transaction account. Set the concrete transaction commodity to the first found of: The template transaction's commodity The commodity of the first split with a credit or debit string The commodity of the first split. --- libgnucash/app-utils/gnc-sx-instance-model.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libgnucash/app-utils/gnc-sx-instance-model.c b/libgnucash/app-utils/gnc-sx-instance-model.c index 4e114eb11b..1f69e1ee27 100644 --- a/libgnucash/app-utils/gnc-sx-instance-model.c +++ b/libgnucash/app-utils/gnc-sx-instance-model.c @@ -1206,7 +1206,8 @@ static gnc_commodity* get_transaction_currency(SxTxnCreationData *creation_data, SchedXaction *sx, Transaction *template_txn) { - gnc_commodity *first_currency = NULL, *first_cmdty = NULL; + gnc_commodity *first_currency = NULL, *first_cmdty = NULL, + *fallback_cmdty = NULL; gboolean err_flag = FALSE, txn_cmdty_in_splits = FALSE; gnc_commodity *txn_cmdty = xaccTransGetCurrency (template_txn); GList* txn_splits = xaccTransGetSplitList (template_txn); @@ -1234,6 +1235,9 @@ get_transaction_currency(SxTxnCreationData *creation_data, /* Don't consider the commodity of a transaction that has * neither a credit nor a debit formula. */ + if (!fallback_cmdty) + fallback_cmdty = xaccAccountGetCommodity (split_account); + if (split_is_marker(t_split)) continue; @@ -1256,9 +1260,11 @@ get_transaction_currency(SxTxnCreationData *creation_data, if (first_currency && (!txn_cmdty_in_splits || !gnc_commodity_is_currency (txn_cmdty))) return first_currency; - if (!txn_cmdty_in_splits) + if (!txn_cmdty_in_splits && first_cmdty) return first_cmdty; - return txn_cmdty; + if (txn_cmdty) + return txn_cmdty; + return fallback_cmdty; } static gboolean