bug fixes

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9181 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2003-08-26 13:53:54 +00:00
parent bddd29cfe9
commit 883aa58c1b
2 changed files with 40 additions and 39 deletions

View File

@ -89,16 +89,12 @@ void
xaccAccountScrubDoubleBalance (Account *acc) xaccAccountScrubDoubleBalance (Account *acc)
{ {
LotList *node; LotList *node;
if (!acc) return; if (!acc) return;
ENTER ("acc=%s", acc->accountName); ENTER ("acc=%s", acc->accountName);
for (node = acc->lots; node; node=node->next) for (node = acc->lots; node; node=node->next)
{ {
GNCLot *lot = node->data; GNCLot *lot = node->data;
/* We examine only closed lots */
if (FALSE == gnc_lot_is_closed (lot)) continue;
xaccLotScrubDoubleBalance (lot); xaccLotScrubDoubleBalance (lot);
} }
LEAVE ("acc=%s", acc->accountName); LEAVE ("acc=%s", acc->accountName);
@ -148,19 +144,23 @@ xaccLotScrubDoubleBalance (GNCLot *lot)
} }
/* Now, total up the values */ /* Now, total up the values */
value = gnc_numeric_add (value, xaccSplitGetValue (s), value = gnc_numeric_add_fixed (value, xaccSplitGetValue (s));
GNC_DENOM_AUTO, GNC_DENOM_LCD);
PINFO ("Split value=%s Accum Lot value=%s", PINFO ("Split value=%s Accum Lot value=%s",
gnc_numeric_to_string (xaccSplitGetValue(s)), gnc_numeric_to_string (xaccSplitGetValue(s)),
gnc_numeric_to_string (value)); gnc_numeric_to_string (value));
}
if (FALSE == gnc_numeric_equal (value, zero)) if (FALSE == gnc_numeric_equal (value, zero))
{ {
/* Unhandled error condition. Not sure what to do here, /* Unhandled error condition. Not sure what to do here,
* Since the ComputeCapGains should have gotten it right. */ * Since the ComputeCapGains should have gotten it right.
* I suppose there might be small rounding errors, a penny or two,
* the ideal thing would to figure out why there's a roudning
* error, and fix that.
*/
PERR ("Closed lot fails to double-balance !!\n"); PERR ("Closed lot fails to double-balance !!\n");
} }
}
LEAVE ("lot=%s", kvp_frame_get_string (gnc_lot_get_slots (lot), "/title")); LEAVE ("lot=%s", kvp_frame_get_string (gnc_lot_get_slots (lot), "/title"));
} }

View File

@ -38,11 +38,13 @@
* cap gains have. * cap gains have.
ToDo List: ToDo List:
o Need to have some sort of modified event handling watcher, o Need to use a 'gains dirty' flag: A 'dirty' flag on the source
so that the peered gains split gets notified when the source split indicates that the gains transaction needs to be recomputed.
split gets modified, etc. etc. Another flag, the gains transaction flag, marks the split as
Also, need to use xaccTransSetReadOnly on the gains split. being a gains split, and that the source transaction should be
XXX one readonly usage is not i18n'ed !! checked for dirtiness before returning the date, the amount, the
value, etc. Finally, these flags make amount and value read-only
for the gains splits. (the memo is user-modifieable).
o If the amount in a split is changed, then the lot has to be recomputed. o If the amount in a split is changed, then the lot has to be recomputed.
This has a potential trickle-through effect on all later lots. This has a potential trickle-through effect on all later lots.
@ -599,18 +601,6 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc)
*/ */
lot_split = xaccSplitGetCapGainsSplit (split); lot_split = xaccSplitGetCapGainsSplit (split);
/* Make sure the existing gains trans has the correct currency,
* just in case someone screwed with it! If not, blow it up. */
if (lot_split &&
(FALSE == gnc_commodity_equiv (currency,
xaccTransGetCurrency(lot_split->parent))))
{
trans = lot_split->parent;
xaccTransBeginEdit (trans);
xaccTransDestroy (trans);
xaccTransCommitEdit (trans);
lot_split = NULL;
}
if (NULL == lot_split) if (NULL == lot_split)
{ {
Account *lot_acc = lot->account; Account *lot_acc = lot->account;
@ -661,6 +651,11 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc)
trans = lot_split->parent; trans = lot_split->parent;
gain_split = xaccSplitGetOtherSplit (lot_split); gain_split = xaccSplitGetOtherSplit (lot_split);
xaccTransBeginEdit (trans); xaccTransBeginEdit (trans);
xaccTransClearReadOnly (trans);
/* Make sure the existing gains trans has the correct currency,
* just in case someone screwed with it! */
xaccTransSetCurrency (trans, currency);
} }
/* Common to both */ /* Common to both */
@ -669,11 +664,15 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc)
xaccTransSetDateEnteredSecs (trans, time(0)); xaccTransSetDateEnteredSecs (trans, time(0));
xaccSplitSetAmount (lot_split, zero); xaccSplitSetAmount (lot_split, zero);
xaccSplitSetValue (lot_split, gnc_numeric_neg (value)); xaccSplitSetValue (lot_split, value);
gnc_lot_add_split (lot, lot_split); gnc_lot_add_split (lot, lot_split);
value = gnc_numeric_neg (value);
xaccSplitSetAmount (gain_split, value); xaccSplitSetAmount (gain_split, value);
xaccSplitSetValue (gain_split, value); xaccSplitSetValue (gain_split, value);
/* XXX this is wrong; we want to make amount read-only only */
xaccTransSetReadOnly (trans, _("Capital Gains"));
xaccTransCommitEdit (trans); xaccTransCommitEdit (trans);
} }
@ -686,11 +685,13 @@ gnc_numeric
xaccSplitGetCapGains(Split * split) xaccSplitGetCapGains(Split * split)
{ {
if (!split) return gnc_numeric_zero(); if (!split) return gnc_numeric_zero();
split = xaccSplitGetCapGainsSplit (split);
if (!split) return gnc_numeric_zero();
/* XXX Do *not! recomp gains every time; use a 'dirty' flag instead */ /* XXX Do *not! recomp gains every time; use a 'dirty' flag instead */
xaccSplitComputeCapGains (split, NULL); xaccSplitComputeCapGains (split, NULL);
split = xaccSplitGetCapGainsSplit (split);
if (!split) return gnc_numeric_zero();
return split->value; return split->value;
} }