mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
add some debug statements,
audit the math usage, tweak the scrub routines to get rid of the no-root error message (some debugging printfs remain, which I'll remove later) git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@10117 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
afd64bc58f
commit
5870f0d581
@ -144,9 +144,19 @@ xaccTransScrubOrphans (Transaction *trans)
|
||||
if (split->acc)
|
||||
{
|
||||
TransScrubOrphansFast (trans, xaccAccountGetRoot(split->acc));
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we got to here, then *none* of the splits belonged to an
|
||||
* account. Not a happy situation. We should dig an account
|
||||
* out of the book the transaction belongs to.
|
||||
* XXX we should probably *always* to this, instead of the above loop!
|
||||
*/
|
||||
PINFO ("Free Floating Transaction!");
|
||||
QofBook *book = xaccTransGetBook (trans);
|
||||
AccountGroup *root = xaccGetAccountGroup (book);
|
||||
TransScrubOrphansFast (trans, root);
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
@ -344,7 +354,27 @@ xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
|
||||
if (!root)
|
||||
{
|
||||
Split *s = slist->data;
|
||||
if (NULL == s->acc)
|
||||
{
|
||||
/* This should never occur, since xaccTransScrubSplits()
|
||||
* above should have fixed things up. */
|
||||
PERR ("Split is not assigned to any account");
|
||||
}
|
||||
root = xaccAccountGetRoot (s->acc);
|
||||
if (NULL == root)
|
||||
{
|
||||
/* This should never occur, accounts are always
|
||||
* in an account group */
|
||||
PERR ("Can't find root account");
|
||||
QofBook *book = xaccTransGetBook (trans);
|
||||
root = xaccGetAccountGroup (book);
|
||||
}
|
||||
if (NULL == root)
|
||||
{
|
||||
/* This can't occur, things should be in books */
|
||||
PERR ("Bad data corruption, no root account in book");
|
||||
return;
|
||||
}
|
||||
}
|
||||
account = xaccScrubUtilityGetOrMakeAccount (root,
|
||||
trans->common_currency, _("Imbalance"));
|
||||
|
@ -121,6 +121,8 @@ xaccLotFill (GNCLot *lot)
|
||||
{
|
||||
Split *subsplit;
|
||||
|
||||
PINFO ("duuuuude split=%s %s", gnc_numeric_to_string
|
||||
(split->amount),gnc_numeric_to_string (split->value));
|
||||
subsplit = xaccSplitAssignToLot (split, lot);
|
||||
if (subsplit == split)
|
||||
{
|
||||
@ -184,7 +186,7 @@ xaccLotScrubDoubleBalance (GNCLot *lot)
|
||||
|
||||
/* Now, total up the values */
|
||||
value = gnc_numeric_add (value, xaccSplitGetValue (s),
|
||||
GNC_DENOM_AUTO, GNC_DENOM_EXACT);
|
||||
GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
|
||||
PINFO ("Split=%p value=%s Accum Lot value=%s", s,
|
||||
gnc_numeric_to_string (s->value),
|
||||
gnc_numeric_to_string (value));
|
||||
@ -257,9 +259,21 @@ xaccScrubSubSplitPrice (Split *split, int maxmult, int maxamtscu)
|
||||
dst_amt = xaccSplitGetAmount (s);
|
||||
dst_val = xaccSplitGetValue (s);
|
||||
target_val = gnc_numeric_mul (dst_amt, src_val,
|
||||
GNC_DENOM_AUTO, GNC_DENOM_REDUCE);
|
||||
GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);
|
||||
target_val = gnc_numeric_div (target_val, src_amt,
|
||||
scu, GNC_DENOM_EXACT);
|
||||
scu, GNC_HOW_DENOM_EXACT|GNC_HOW_RND_ROUND);
|
||||
if (gnc_numeric_check (target_val))
|
||||
{
|
||||
PERR ("Numeric overflow of value\n"
|
||||
"\tAcct=%s txn=%s\n"
|
||||
"\tdst_amt=%s src_val=%s src_amt=%s\n",
|
||||
xaccAccountGetName (s->acc),
|
||||
xaccTransGetDescription(txn),
|
||||
gnc_numeric_to_string(dst_amt),
|
||||
gnc_numeric_to_string(src_val),
|
||||
gnc_numeric_to_string(src_amt));
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If the required price changes are 'small', do nothing.
|
||||
* That is a case that the user will have to deal with
|
||||
|
@ -445,12 +445,24 @@ xaccSplitAssignToLot (Split *split, GNCLot *lot)
|
||||
*/
|
||||
val_tot = split->value;
|
||||
val_a = gnc_numeric_mul (amt_a, val_tot,
|
||||
GNC_DENOM_AUTO, GNC_DENOM_REDUCE);
|
||||
GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);
|
||||
tmp = gnc_numeric_div (val_a, amt_tot,
|
||||
gnc_numeric_denom(val_tot), GNC_DENOM_EXACT);
|
||||
gnc_numeric_denom(val_tot),
|
||||
GNC_HOW_RND_ROUND| GNC_HOW_DENOM_EXACT);
|
||||
|
||||
val_a = tmp;
|
||||
val_b = gnc_numeric_sub_fixed (val_tot, val_a);
|
||||
if (gnc_numeric_check(val_a))
|
||||
{
|
||||
PERR("Numeric overflow\n"
|
||||
"Acct=%s Txn=%s\n"
|
||||
"\tval_tot=%s amt_a=%s amt_tot=%s\n",
|
||||
xaccAccountGetName(acc),
|
||||
xaccTransGetDescription(trans),
|
||||
gnc_numeric_to_string(val_tot),
|
||||
gnc_numeric_to_string(amt_a),
|
||||
gnc_numeric_to_string(amt_tot));
|
||||
}
|
||||
|
||||
PINFO ("split value is = %s = %s + %s",
|
||||
gnc_numeric_to_string(val_tot),
|
||||
@ -616,6 +628,10 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc)
|
||||
split->gains_split, split->gains,
|
||||
kvp_frame_get_string (gnc_lot_get_slots (lot), "/title"));
|
||||
|
||||
PINFO ("duude split amt=%s val=%s \n",
|
||||
gnc_numeric_to_string (split->amount),
|
||||
gnc_numeric_to_string (split->value));
|
||||
|
||||
/* Make sure the status flags and pointers are initialized */
|
||||
if (GAINS_STATUS_UNKNOWN == split->gains) xaccSplitDetermineGainStatus(split);
|
||||
if (pcy->PolicyIsOpeningSplit (pcy, lot, split))
|
||||
@ -707,6 +723,10 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc)
|
||||
pcy->PolicyGetLotOpening (pcy, lot, &opening_amount, &opening_value,
|
||||
&opening_currency);
|
||||
|
||||
PINFO ("duude lot opener amt=%s val=%s \n",
|
||||
gnc_numeric_to_string (opening_amount),
|
||||
gnc_numeric_to_string (opening_value));
|
||||
|
||||
/* Check to make sure the lot-opening currency and this split
|
||||
* use the same currency */
|
||||
if (FALSE == gnc_commodity_equiv (currency, opening_currency))
|
||||
@ -747,11 +767,13 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc)
|
||||
* cap_gain = current_value - cost_basis
|
||||
*/
|
||||
value = gnc_numeric_mul (opening_value, split->amount,
|
||||
GNC_DENOM_AUTO, GNC_RND_NEVER|GNC_DENOM_REDUCE);
|
||||
GNC_DENOM_AUTO,
|
||||
GNC_HOW_RND_NEVER|GNC_HOW_DENOM_REDUCE);
|
||||
value = gnc_numeric_div (value, opening_amount,
|
||||
gnc_numeric_denom(opening_value), GNC_DENOM_EXACT);
|
||||
gnc_numeric_denom(opening_value),
|
||||
GNC_HOW_DENOM_EXACT|GNC_HOW_RND_ROUND);
|
||||
value = gnc_numeric_sub (value, split->value,
|
||||
GNC_DENOM_AUTO, GNC_DENOM_LCD);
|
||||
GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED);
|
||||
PINFO ("Open amt=%s val=%s; split amt=%s val=%s; gains=%s\n",
|
||||
gnc_numeric_to_string (opening_amount),
|
||||
gnc_numeric_to_string (opening_value),
|
||||
@ -760,7 +782,16 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc)
|
||||
gnc_numeric_to_string (value));
|
||||
if (gnc_numeric_check (value))
|
||||
{
|
||||
PERR ("Numeric overflow during gains calculation");
|
||||
PERR ("Numeric overflow during gains calculation\n"
|
||||
"Acct=%s Txn=%s\n"
|
||||
"\tOpen amt=%s val=%s\n\tsplit amt=%s val=%s\n\tgains=%s\n",
|
||||
xaccAccountGetName(split->acc),
|
||||
xaccTransGetDescription(split->parent),
|
||||
gnc_numeric_to_string (opening_amount),
|
||||
gnc_numeric_to_string (opening_value),
|
||||
gnc_numeric_to_string (split->amount),
|
||||
gnc_numeric_to_string (split->value),
|
||||
gnc_numeric_to_string (value));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -875,6 +906,7 @@ gnc_numeric
|
||||
xaccSplitGetCapGains(Split * split)
|
||||
{
|
||||
if (!split) return gnc_numeric_zero();
|
||||
ENTER("(split=%p)", split);
|
||||
|
||||
if (GAINS_STATUS_UNKNOWN == split->gains) xaccSplitDetermineGainStatus(split);
|
||||
if ((split->gains & GAINS_STATUS_A_VDIRTY) ||
|
||||
@ -892,6 +924,7 @@ xaccSplitGetCapGains(Split * split)
|
||||
split = split->gains_split;
|
||||
}
|
||||
|
||||
LEAVE("(split=%p)", split);
|
||||
if (!split) return gnc_numeric_zero();
|
||||
|
||||
return split->value;
|
||||
@ -910,6 +943,7 @@ xaccLotComputeCapGains (GNCLot *lot, Account *gain_acc)
|
||||
* then the cap gains are changed. To capture this, we need
|
||||
* to mark all splits dirty if the opening splits are dirty. */
|
||||
|
||||
ENTER("(lot=%p)", lot);
|
||||
pcy = lot->account->policy;
|
||||
for (node=lot->splits; node; node=node->next)
|
||||
{
|
||||
@ -939,6 +973,7 @@ xaccLotComputeCapGains (GNCLot *lot, Account *gain_acc)
|
||||
Split *s = node->data;
|
||||
xaccSplitComputeCapGains (s, gain_acc);
|
||||
}
|
||||
LEAVE("(lot=%p)", lot);
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
@ -1002,6 +1037,7 @@ xaccTransScrubGains (Transaction *trans, Account *gain_acc)
|
||||
{
|
||||
SplitList *node;
|
||||
|
||||
ENTER("(trans=%p)", trans);
|
||||
/* Lock down posted date, its to be synced to the posted date
|
||||
* for the source of the cap gains. */
|
||||
xaccScrubGainsDate(trans);
|
||||
@ -1036,6 +1072,7 @@ restart:
|
||||
xaccSplitComputeCapGains (split, gain_acc);
|
||||
}
|
||||
}
|
||||
LEAVE("(trans=%p)", trans);
|
||||
}
|
||||
|
||||
/* =========================== END OF FILE ======================= */
|
||||
|
Loading…
Reference in New Issue
Block a user