mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
bug fixes
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9181 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
bddd29cfe9
commit
883aa58c1b
@ -74,9 +74,9 @@ restart_loop:
|
|||||||
{
|
{
|
||||||
Split * split = node->data;
|
Split * split = node->data;
|
||||||
|
|
||||||
/* If already in lot, then no-op */
|
/* If already in lot, then no-op */
|
||||||
if (split->lot) continue;
|
if (split->lot) continue;
|
||||||
if (xaccSplitFIFOAssignToLot (split)) goto restart_loop;
|
if (xaccSplitFIFOAssignToLot (split)) goto restart_loop;
|
||||||
}
|
}
|
||||||
xaccAccountCommitEdit (acc);
|
xaccAccountCommitEdit (acc);
|
||||||
LEAVE ("acc=%s", acc->accountName);
|
LEAVE ("acc=%s", acc->accountName);
|
||||||
@ -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);
|
||||||
@ -121,7 +117,7 @@ xaccLotScrubDoubleBalance (GNCLot *lot)
|
|||||||
for (snode = lot->splits; snode; snode=snode->next)
|
for (snode = lot->splits; snode; snode=snode->next)
|
||||||
{
|
{
|
||||||
Split *s = snode->data;
|
Split *s = snode->data;
|
||||||
xaccSplitComputeCapGains (s, NULL);
|
xaccSplitComputeCapGains (s, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We double-check only closed lots */
|
/* We double-check only closed lots */
|
||||||
@ -139,27 +135,31 @@ xaccLotScrubDoubleBalance (GNCLot *lot)
|
|||||||
}
|
}
|
||||||
if (FALSE == gnc_commodity_equiv (currency, trans->common_currency))
|
if (FALSE == gnc_commodity_equiv (currency, trans->common_currency))
|
||||||
{
|
{
|
||||||
/* This lot has mixed currencies. Can't double-balance.
|
/* This lot has mixed currencies. Can't double-balance.
|
||||||
* Silently punt */
|
* Silently punt */
|
||||||
PWARN ("Lot with multiple currencies:\n"
|
PWARN ("Lot with multiple currencies:\n"
|
||||||
"\ttrans=%s curr=%s\n", xaccTransGetDescription(trans),
|
"\ttrans=%s curr=%s\n", xaccTransGetDescription(trans),
|
||||||
gnc_commodity_get_fullname(trans->common_currency));
|
gnc_commodity_get_fullname(trans->common_currency));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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))
|
}
|
||||||
{
|
|
||||||
/* Unhandled error condition. Not sure what to do here,
|
if (FALSE == gnc_numeric_equal (value, zero))
|
||||||
* Since the ComputeCapGains should have gotten it right. */
|
{
|
||||||
PERR ("Closed lot fails to double-balance !!\n");
|
/* 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"));
|
LEAVE ("lot=%s", kvp_frame_get_string (gnc_lot_get_slots (lot), "/title"));
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user