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

@ -74,9 +74,9 @@ restart_loop:
{
Split * split = node->data;
/* If already in lot, then no-op */
if (split->lot) continue;
if (xaccSplitFIFOAssignToLot (split)) goto restart_loop;
/* If already in lot, then no-op */
if (split->lot) continue;
if (xaccSplitFIFOAssignToLot (split)) goto restart_loop;
}
xaccAccountCommitEdit (acc);
LEAVE ("acc=%s", acc->accountName);
@ -89,16 +89,12 @@ void
xaccAccountScrubDoubleBalance (Account *acc)
{
LotList *node;
if (!acc) return;
ENTER ("acc=%s", acc->accountName);
for (node = acc->lots; node; node=node->next)
{
GNCLot *lot = node->data;
/* We examine only closed lots */
if (FALSE == gnc_lot_is_closed (lot)) continue;
xaccLotScrubDoubleBalance (lot);
}
LEAVE ("acc=%s", acc->accountName);
@ -121,7 +117,7 @@ xaccLotScrubDoubleBalance (GNCLot *lot)
for (snode = lot->splits; snode; snode=snode->next)
{
Split *s = snode->data;
xaccSplitComputeCapGains (s, NULL);
xaccSplitComputeCapGains (s, NULL);
}
/* We double-check only closed lots */
@ -139,27 +135,31 @@ xaccLotScrubDoubleBalance (GNCLot *lot)
}
if (FALSE == gnc_commodity_equiv (currency, trans->common_currency))
{
/* This lot has mixed currencies. Can't double-balance.
* Silently punt */
/* This lot has mixed currencies. Can't double-balance.
* Silently punt */
PWARN ("Lot with multiple currencies:\n"
"\ttrans=%s curr=%s\n", xaccTransGetDescription(trans),
gnc_commodity_get_fullname(trans->common_currency));
break;
break;
}
/* Now, total up the values */
value = gnc_numeric_add (value, xaccSplitGetValue (s),
GNC_DENOM_AUTO, GNC_DENOM_LCD);
value = gnc_numeric_add_fixed (value, xaccSplitGetValue (s));
PINFO ("Split value=%s Accum Lot value=%s",
gnc_numeric_to_string (xaccSplitGetValue(s)),
gnc_numeric_to_string (value));
if (FALSE == gnc_numeric_equal (value, zero))
{
/* Unhandled error condition. Not sure what to do here,
* Since the ComputeCapGains should have gotten it right. */
PERR ("Closed lot fails to double-balance !!\n");
}
}
if (FALSE == gnc_numeric_equal (value, zero))
{
/* Unhandled error condition. Not sure what to do here,
* 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");
}
LEAVE ("lot=%s", kvp_frame_get_string (gnc_lot_get_slots (lot), "/title"));

View File

@ -38,11 +38,13 @@
* cap gains have.
ToDo List:
o Need to have some sort of modified event handling watcher,
so that the peered gains split gets notified when the source
split gets modified, etc. etc.
Also, need to use xaccTransSetReadOnly on the gains split.
XXX one readonly usage is not i18n'ed !!
o Need to use a 'gains dirty' flag: A 'dirty' flag on the source
split indicates that the gains transaction needs to be recomputed.
Another flag, the gains transaction flag, marks the split as
being a gains split, and that the source transaction should be
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.
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);
/* 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)
{
Account *lot_acc = lot->account;
@ -661,6 +651,11 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc)
trans = lot_split->parent;
gain_split = xaccSplitGetOtherSplit (lot_split);
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 */
@ -669,11 +664,15 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc)
xaccTransSetDateEnteredSecs (trans, time(0));
xaccSplitSetAmount (lot_split, zero);
xaccSplitSetValue (lot_split, gnc_numeric_neg (value));
xaccSplitSetValue (lot_split, value);
gnc_lot_add_split (lot, lot_split);
value = gnc_numeric_neg (value);
xaccSplitSetAmount (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);
}
@ -686,11 +685,13 @@ gnc_numeric
xaccSplitGetCapGains(Split * split)
{
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 */
xaccSplitComputeCapGains (split, NULL);
split = xaccSplitGetCapGainsSplit (split);
if (!split) return gnc_numeric_zero();
return split->value;
}