Improve stock-split type detection

Noted split_type field in Split exists but is not used...

Reset split_type field's data type to hold the type of the getter.
Implemented xaccSplitIsStockSplit() abstraction to limit the split type string reference to Split.cpp and propagated it's use.
This commit is contained in:
Sherlock committed 2026-07-09 01:12:49 -07:00
1 parent 0d5c74b868
commit 254ec4b4d0
5 files changed
+37 -16

No files matched your search

@@ -1546,7 +1546,7 @@ gnc_split_register_get_mxfrm_entry (VirtualLocation virt_loc,
if (s)
name = g_strdup (SPLIT_TRANS_STR);
else if (g_strcmp0 ("stock-split", xaccSplitGetType (split)) == 0)
else if (xaccSplitIsStockSplit (split))
name = g_strdup (STOCK_SPLIT_STR);
else
name = g_strdup ("");
@@ -1588,7 +1588,7 @@ gnc_split_register_get_mxfrm_help (VirtualLocation virt_loc,
if (s)
help = _ ("This transaction has multiple splits; "
"press the Split button to see them all");
else if (g_strcmp0 ("stock-split", xaccSplitGetType (split)) == 0)
else if (xaccSplitIsStockSplit (split))
help = _ ("This transaction is a stock split; "
"press the Split button to see details");
else
@@ -2080,7 +2080,7 @@ gnc_split_register_get_debcred_io_flags (VirtualLocation virt_loc,
split = gnc_split_register_get_split (reg, virt_loc.vcell_loc);
if (g_strcmp0 ("stock-split", xaccSplitGetType (split)) == 0)
if (xaccSplitIsStockSplit (split))
return XACC_CELL_ALLOW_NONE;
return XACC_CELL_ALLOW_ALL;
+27 -10
View File
@@ -129,6 +129,7 @@ gnc_split_init(Split* split)
split->noclosing_balance = gnc_numeric_zero();
split->adjusted_amount = gnc_numeric_zero();
split->split_type = nullptr;
split->gains = GAINS_STATUS_UNKNOWN;
split->gains_split = nullptr;
@@ -523,6 +524,7 @@ xaccSplitReinit(Split * split)
split->noclosing_balance = gnc_numeric_zero();
split->adjusted_amount = gnc_numeric_zero();
split->split_type = nullptr;
qof_instance_set_idata(split, 0);
@@ -609,6 +611,7 @@ xaccSplitCloneNoKvp (const Split *s)
split->reconciled_balance = s->reconciled_balance;
split->noclosing_balance = s->noclosing_balance;
split->adjusted_amount = s->adjusted_amount;
split->split_type = s->split_type;
split->gains = GAINS_STATUS_UNKNOWN;
split->gains_split = nullptr;
@@ -695,6 +698,7 @@ xaccSplitDump (const Split *split, const char *tag)
gnc_numeric_to_string(split->reconciled_balance));
printf(" NoClose: %s\n", gnc_numeric_to_string(split->noclosing_balance));
printf(" AdjAmt: %s\n", gnc_numeric_to_string(split->adjusted_amount));
printf(" Type: %s\n", split->split_type ? split->split_type : "(null)");
printf(" idata: %x\n", qof_instance_get_idata(split));
}
#endif
@@ -756,6 +760,7 @@ xaccFreeSplit (Split *split)
split->orig_acc = nullptr;
split->adjusted_amount = gnc_numeric_zero();
split->split_type = nullptr;
split->date_reconciled = 0;
G_OBJECT_CLASS (QOF_INSTANCE_GET_CLASS (&split->inst))->dispose(G_OBJECT (split));
@@ -2028,20 +2033,25 @@ xaccSplitGetBook (const Split *split)
}
const char *
xaccSplitGetType(const Split *s)
xaccSplitGetType(Split *s)
{
if (!s) return nullptr;
auto type{qof_instance_get_path_kvp<const char*> (QOF_INSTANCE(s), {"split-type"})};
if (!s->split_type)
{
auto type{qof_instance_get_path_kvp<const char*> (QOF_INSTANCE(s), {"split-type"})};
if (!type || !g_strcmp0 (*type, split_type_normal))
return split_type_normal;
if (!g_strcmp0 (*type, split_type_stock_split))
return split_type_stock_split;
PERR ("unexpected split-type %s, reset to normal.", *type);
return split_type_normal;
if (!type || !g_strcmp0 (*type, split_type_normal))
s->split_type = split_type_normal;
else if (!g_strcmp0 (*type, split_type_stock_split))
s->split_type = split_type_stock_split;
else
{
PERR ("unexpected split-type %s, reset to normal.", *type);
s->split_type = split_type_normal;
}
}
return s->split_type;
}
/* reconfigure a split to be a stock split - after this, you shouldn't
@@ -2052,6 +2062,7 @@ xaccSplitMakeStockSplit(Split *s)
xaccTransBeginEdit (s->parent);
s->value = gnc_numeric_zero();
s->split_type = split_type_stock_split;
qof_instance_set_path_kvp<const char*> (QOF_INSTANCE(s), g_strdup(split_type_stock_split),
{"split-type"});
SET_GAINS_VDIRTY(s);
@@ -2060,6 +2071,12 @@ xaccSplitMakeStockSplit(Split *s)
xaccTransCommitEdit(s->parent);
}
gboolean
xaccSplitIsStockSplit (Split *s)
{
return g_strcmp0(split_type_stock_split, xaccSplitGetType(s)) == 0;
}
void
xaccSplitAddPeerSplit (Split *split, const Split *other_split,
time64 timestamp)
+5 -1
View File
@@ -428,12 +428,16 @@ gboolean xaccIsPeerSplit (const Split *split_1, const Split *split_2);
*/
/** Returns the split type, which is either the string "normal", or
* "stock-split" for a split from a stock split (pun intended? :-). */
const char *xaccSplitGetType(const Split *s);
const char *xaccSplitGetType(Split *s);
/** Mark a split to be of type stock split - after this, you shouldn't
modify the value anymore, just the amount. */
void xaccSplitMakeStockSplit(Split *s);
/** Returns true if the split is of type stock split
*/
gboolean xaccSplitIsStockSplit(Split *s);
/**
* The xaccSplitOrder(sa,sb) method is useful for sorting.
* if sa and sb have different transactions, return their xaccTransOrder
+1 -1
View File
@@ -115,7 +115,7 @@ struct split_s
gnc_numeric value;
gnc_numeric amount;
const gchar * split_type;
const char *split_type;
/* -------------------------------------------------------------- */
/* Below follow some 'temporary' fields */
+1 -1
View File
@@ -581,7 +581,7 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc)
return;
}
if (g_strcmp0 ("stock-split", xaccSplitGetType (split)) == 0)
if (xaccSplitIsStockSplit (split))
{
LEAVE ("Stock split split, returning.");
return;