gnucash maint: Correct detection of marker commodity splits.
John Ralls
jralls at code.gnucash.org
Thu Dec 17 19:40:37 EST 2015
Updated via https://github.com/Gnucash/gnucash/commit/8d904c12 (commit)
from https://github.com/Gnucash/gnucash/commit/5f0cb073 (commit)
commit 8d904c1209d3973f5f2bbf948c0c88c436dbdebc
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Dec 17 16:38:35 2015 -0800
Correct detection of marker commodity splits.
The splits don't have an amount until after the formula is parsed, so
use the absence of both a credit and debit formula to indicate a marker.
diff --git a/src/app-utils/gnc-sx-instance-model.c b/src/app-utils/gnc-sx-instance-model.c
index 6d8a24d..b509068 100644
--- a/src/app-utils/gnc-sx-instance-model.c
+++ b/src/app-utils/gnc-sx-instance-model.c
@@ -193,7 +193,7 @@ _get_vars_helper(Transaction *txn, void *var_hash_data)
gnc_commodity *split_cmdty = NULL;
GncGUID *acct_guid;
Account *acct;
- gnc_numeric split_amount;
+ gboolean split_is_marker = TRUE;
s = (Split*)split_list->data;
kvpf = xaccSplitGetSlots(s);
@@ -204,30 +204,6 @@ _get_vars_helper(Transaction *txn, void *var_hash_data)
acct_guid = kvp_value_get_guid(kvp_val);
acct = xaccAccountLookup(acct_guid, gnc_get_current_book());
split_cmdty = xaccAccountGetCommodity(acct);
- split_amount = xaccSplitGetAmount(s);
- if (!gnc_numeric_zero_p(split_amount) && first_cmdty == NULL)
- {
- first_cmdty = split_cmdty;
- }
-
- if (!gnc_numeric_zero_p(split_amount) &&
- ! gnc_commodity_equal(split_cmdty, first_cmdty))
- {
- GncSxVariable *var;
- GString *var_name;
- const gchar *split_mnemonic, *first_mnemonic;
-
- var_name = g_string_sized_new(16);
- split_mnemonic = gnc_commodity_get_mnemonic(split_cmdty);
- first_mnemonic = gnc_commodity_get_mnemonic(first_cmdty);
- g_string_printf(var_name, "%s -> %s",
- split_mnemonic ? split_mnemonic : "(null)",
- first_mnemonic ? first_mnemonic : "(null)");
- var = gnc_sx_variable_new(g_strdup(var_name->str));
- g_hash_table_insert(var_hash, g_strdup(var->name), var);
- g_string_free(var_name, TRUE);
- }
-
// existing... ------------------------------------------
kvp_val = kvp_frame_get_slot_path(kvpf,
GNC_SX_ID,
@@ -239,6 +215,7 @@ _get_vars_helper(Transaction *txn, void *var_hash_data)
if (str && strlen(str) != 0)
{
gnc_sx_parse_vars_from_formula(str, var_hash, NULL);
+ split_is_marker = FALSE;
}
}
@@ -252,8 +229,32 @@ _get_vars_helper(Transaction *txn, void *var_hash_data)
if (str && strlen(str) != 0)
{
gnc_sx_parse_vars_from_formula(str, var_hash, NULL);
+ split_is_marker = FALSE;
}
}
+ if (!split_is_marker && first_cmdty == NULL)
+ {
+ first_cmdty = split_cmdty;
+ }
+
+ if (!split_is_marker &&
+ ! gnc_commodity_equal(split_cmdty, first_cmdty))
+ {
+ GncSxVariable *var;
+ GString *var_name;
+ const gchar *split_mnemonic, *first_mnemonic;
+
+ var_name = g_string_sized_new(16);
+ split_mnemonic = gnc_commodity_get_mnemonic(split_cmdty);
+ first_mnemonic = gnc_commodity_get_mnemonic(first_cmdty);
+ g_string_printf(var_name, "%s -> %s",
+ split_mnemonic ? split_mnemonic : "(null)",
+ first_mnemonic ? first_mnemonic : "(null)");
+ var = gnc_sx_variable_new(g_strdup(var_name->str));
+ g_hash_table_insert(var_hash, g_strdup(var->name), var);
+ g_string_free(var_name, TRUE);
+ }
+
}
return 0;
Summary of changes:
src/app-utils/gnc-sx-instance-model.c | 51 ++++++++++++++++++-----------------
1 file changed, 26 insertions(+), 25 deletions(-)
More information about the gnucash-changes
mailing list