mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-10-25 07:37:39 -05:00
Add adjusted_amount field to split
The adjusted_amount field of a split will hold the stock split adjusted amount. The adjusted amount is initially the same as the original amount. When the account balances are recomputed and a stock-split split type is encountered, the ratio of the stock split will be applied to the preceding splits adjusted_amounts. If there are no stock splits in the split's account, the adjusted amount remains the original amount.
This commit is contained in:
1 parent
3fbde665a6
commit
0d5c74b868
3 files changed
+40
No files matched your search
@@ -128,6 +128,8 @@ gnc_split_init(Split* split)
|
||||
split->reconciled_balance = gnc_numeric_zero();
|
||||
split->noclosing_balance = gnc_numeric_zero();
|
||||
|
||||
split->adjusted_amount = gnc_numeric_zero();
|
||||
|
||||
split->gains = GAINS_STATUS_UNKNOWN;
|
||||
split->gains_split = nullptr;
|
||||
}
|
||||
@@ -520,6 +522,8 @@ xaccSplitReinit(Split * split)
|
||||
split->reconciled_balance = gnc_numeric_zero();
|
||||
split->noclosing_balance = gnc_numeric_zero();
|
||||
|
||||
split->adjusted_amount = gnc_numeric_zero();
|
||||
|
||||
qof_instance_set_idata(split, 0);
|
||||
|
||||
split->gains = GAINS_STATUS_UNKNOWN;
|
||||
@@ -604,6 +608,7 @@ xaccSplitCloneNoKvp (const Split *s)
|
||||
split->cleared_balance = s->cleared_balance;
|
||||
split->reconciled_balance = s->reconciled_balance;
|
||||
split->noclosing_balance = s->noclosing_balance;
|
||||
split->adjusted_amount = s->adjusted_amount;
|
||||
|
||||
split->gains = GAINS_STATUS_UNKNOWN;
|
||||
split->gains_split = nullptr;
|
||||
@@ -689,6 +694,7 @@ xaccSplitDump (const Split *split, const char *tag)
|
||||
printf(" RBalance: %s\n",
|
||||
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(" idata: %x\n", qof_instance_get_idata(split));
|
||||
}
|
||||
#endif
|
||||
@@ -749,6 +755,8 @@ xaccFreeSplit (Split *split)
|
||||
split->acc = nullptr;
|
||||
split->orig_acc = nullptr;
|
||||
|
||||
split->adjusted_amount = gnc_numeric_zero();
|
||||
|
||||
split->date_reconciled = 0;
|
||||
G_OBJECT_CLASS (QOF_INSTANCE_GET_CLASS (&split->inst))->dispose(G_OBJECT (split));
|
||||
|
||||
@@ -915,6 +923,9 @@ xaccSplitEqual(const Split *sa, const Split *sb,
|
||||
if (!xaccSplitEqualCheckBal ("noclosing ", sa->noclosing_balance,
|
||||
sb->noclosing_balance))
|
||||
return FALSE;
|
||||
if (!xaccSplitEqualCheckBal ("adjusted ", sa->adjusted_amount,
|
||||
sb->adjusted_amount))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!xaccTransEqual(sa->parent, sb->parent, check_guids, check_txn_splits,
|
||||
@@ -1238,6 +1249,7 @@ xaccSplitSetAmount (Split *s, gnc_numeric amt)
|
||||
}
|
||||
else
|
||||
s->amount = amt;
|
||||
s->adjusted_amount = s->amount;
|
||||
|
||||
SET_GAINS_ADIRTY(s);
|
||||
mark_split (s);
|
||||
@@ -1316,6 +1328,21 @@ xaccSplitGetReconciledBalance (const Split *s)
|
||||
return s ? s->reconciled_balance : gnc_numeric_zero();
|
||||
}
|
||||
|
||||
gnc_numeric
|
||||
xaccSplitGetAdjustedAmount (const Split *s)
|
||||
{
|
||||
return s ? s->adjusted_amount : gnc_numeric_zero();
|
||||
}
|
||||
|
||||
void
|
||||
xaccSplitSetAdjustedAmount (Split *s, gnc_numeric amt)
|
||||
{
|
||||
if (!s) return;
|
||||
if (gnc_numeric_check (amt)) return;
|
||||
|
||||
s->adjusted_amount = amt;
|
||||
}
|
||||
|
||||
void
|
||||
xaccSplitSetBaseValue (Split *s, gnc_numeric value,
|
||||
const gnc_commodity * base_currency)
|
||||
|
||||
@@ -345,6 +345,16 @@ gnc_numeric xaccSplitGetClearedBalance (const Split *split);
|
||||
*/
|
||||
gnc_numeric xaccSplitGetReconciledBalance (const Split *split);
|
||||
|
||||
/** Returns the stock-split adjusted amount of the split in the account's commodity.
|
||||
*/
|
||||
gnc_numeric xaccSplitGetAdjustedAmount (const Split *split);
|
||||
|
||||
/** Sets the stock split adjusted amount of a split. Note: The adjusted amount
|
||||
* will be reset when the account is rebalanced.
|
||||
*/
|
||||
void xaccSplitSetAdjustedAmount (Split *split, gnc_numeric amount);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @name Split utility functions
|
||||
|
||||
@@ -128,6 +128,9 @@ struct split_s
|
||||
gnc_numeric noclosing_balance;
|
||||
gnc_numeric cleared_balance;
|
||||
gnc_numeric reconciled_balance;
|
||||
|
||||
/* The stock-split adjusted amount */
|
||||
gnc_numeric adjusted_amount;
|
||||
};
|
||||
|
||||
struct _SplitClass
|
||||
|
||||
Reference in new issue
Block a user