Do not try to compute cap gains if cap gains not possible.

Gains aren't possible if the lot commodity is the same as
the transaction currency.   I think that this should fix
http://bugzilla.gnome.org/show_bug.cgi?id=139677
Untested, let me know.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9976 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2004-05-29 19:09:14 +00:00
parent 894da26df6
commit c11d423065

View File

@ -19,10 +19,10 @@
* Boston, MA 02111-1307, USA gnu@gnu.org *
\********************************************************************/
/* @file Scrub3.c
/** @file Scrub3.c
* @breif Constrain Cap Gains to Track Sources of Gains
* @author Created by Linas Vepstas Sept 2003
* @author Copyright (c) 2003 Linas Vepstas <linas@linas.org>
* @author Copyright (c) 2003,2004 Linas Vepstas <linas@linas.org>
*
* Provides a set of functions and utilities for checking and
* repairing ('scrubbing clean') the usage of Cap Gains
@ -53,6 +53,36 @@
static short module = MOD_LOT;
/* ================================================================= */
/** Cap gains are possible only if the lot commodity is not the same
* as the transaction currency. We assume here that all splits in
* the lot share the same transaction currency, and so we look at
* the first split, and see what it's currency is.
* This routine returns TRUE if cap gains are possible.
*/
static inline gboolean
gains_possible (GNCLot *lot)
{
SplitList *node;
Account *acc;
Split *split;
gboolean comeq;
acc = gnc_lot_get_account (lot);
node = gnc_lot_get_split_list (lot);
if (!node) return FALSE;
split = node->data;
comeq = gnc_commodity_equiv (acc->commodity, split->parent->common_currency);
return (FALSE == comeq);
}
/* ================================================================= */
/* XXX What happens if, as a result of scrubbing, the lot is empty?
* I don't think this is handled properly. I think that what will
* happen is we'll end up with an empty, closed lot ... ?
*/
gboolean
xaccScrubLot (GNCLot *lot)
@ -105,9 +135,18 @@ rethin:
splits_deleted = xaccScrubMergeLotSubSplits (lot);
}
/* Now re-compute cap gains, and then double-check that. */
xaccLotComputeCapGains (lot, NULL);
xaccLotScrubDoubleBalance (lot);
/* Now re-compute cap gains, and then double-check that.
* But we only compute cap-gains if gains are possible;
* that is if the lot commodity is not the same as the
* currency. That is, one can't possibly have gains
* selling dollars for dollars. The business modules
* use lots with lot commodity == lot currency.
*/
if (gains_possible (lot))
{
xaccLotComputeCapGains (lot, NULL);
xaccLotScrubDoubleBalance (lot);
}
xaccAccountCommitEdit(acc);
LEAVE (" deleted=%d", splits_deleted);