partial fix for the failure of the test-lots test case:

Change the FIFO policy to avoid mixed-currency lots.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9977 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2004-05-29 20:06:03 +00:00
parent c11d423065
commit bd7a8b732d
4 changed files with 38 additions and 17 deletions

View File

@ -55,6 +55,10 @@
static short module = MOD_LOT;
/* ============================================================== */
/** Loop over all splits, and make sure that every split
* belongs to some lot. If a split does not belong to
* any lots, poke it into one.
*/
void
xaccAccountAssignLots (Account *acc)
@ -66,10 +70,6 @@ xaccAccountAssignLots (Account *acc)
ENTER ("acc=%s", acc->accountName);
xaccAccountBeginEdit (acc);
/* Loop over all splits, and make sure that every split
* belongs to some lot. If a split does not belong to
* any lots, poke it into one.
*/
restart_loop:
for (node=acc->splits; node; node=node->next)
{
@ -83,7 +83,6 @@ restart_loop:
LEAVE ("acc=%s", acc->accountName);
}
/* ============================================================== */
/** The xaccLotFill() routine attempts to assign splits to the

View File

@ -22,7 +22,7 @@
/** @file cap-gains.c
* @breif Utilities to Automatically Compute Capital Gains/Losses.
* @author Created by Linas Vepstas August 2003
* @author Copyright (c) 2003 Linas Vepstas <linas@linas.org>
* @author Copyright (c) 2003,2004 Linas Vepstas <linas@linas.org>
*
* This file implements the various routines to automatically
* compute and handle Cap Gains/Losses resulting from trading
@ -110,6 +110,7 @@ xaccAccountHasTrades (Account *acc)
struct find_lot_s
{
GNCLot *lot;
gnc_commodity *currency;
Timespec ts;
int (*numeric_pred)(gnc_numeric);
gboolean (*date_pred)(Timespec e, Timespec tr);
@ -145,6 +146,13 @@ finder_helper (GNCLot *lot, gpointer user_data)
s = gnc_lot_get_earliest_split (lot);
trans = s->parent;
if (els->currency &&
(FALSE == gnc_commodity_equiv (els->currency,
trans->common_currency)))
{
return NULL;
}
if (els->date_pred (els->ts, trans->date_posted))
{
els->ts = trans->date_posted;
@ -156,12 +164,14 @@ finder_helper (GNCLot *lot, gpointer user_data)
static inline GNCLot *
xaccAccountFindOpenLot (Account *acc, gnc_numeric sign,
gnc_commodity *currency,
long long guess,
gboolean (*date_pred)(Timespec, Timespec))
{
struct find_lot_s es;
es.lot = NULL;
es.currency = currency;
es.ts.tv_sec = guess;
es.ts.tv_nsec = 0;
es.date_pred = date_pred;
@ -174,24 +184,26 @@ xaccAccountFindOpenLot (Account *acc, gnc_numeric sign,
}
GNCLot *
xaccAccountFindEarliestOpenLot (Account *acc, gnc_numeric sign)
xaccAccountFindEarliestOpenLot (Account *acc, gnc_numeric sign,
gnc_commodity *currency)
{
GNCLot *lot;
ENTER (" sign=%lld/%lld", sign.num, sign.denom);
lot = xaccAccountFindOpenLot (acc, sign,
lot = xaccAccountFindOpenLot (acc, sign, currency,
10000000LL * ((long long) LONG_MAX), earliest_pred);
LEAVE ("found lot=%p %s", lot, gnc_lot_get_title (lot));
return lot;
}
GNCLot *
xaccAccountFindLatestOpenLot (Account *acc, gnc_numeric sign)
xaccAccountFindLatestOpenLot (Account *acc, gnc_numeric sign,
gnc_commodity *currency)
{
GNCLot *lot;
ENTER (" sign=%lld/%lld", sign.num, sign.denom);
lot = xaccAccountFindOpenLot (acc, sign,
lot = xaccAccountFindOpenLot (acc, sign, currency,
-10000000LL * ((long long) LONG_MAX), latest_pred);
LEAVE ("found lot=%p %s", lot, gnc_lot_get_title (lot));
return lot;
@ -539,8 +551,8 @@ xaccSplitAssign (Split *split)
* block is written in the form of a while loop, since we
* may have to bust a split across several lots.
*/
while (split)
{
while (split)
{
PINFO ("have split amount=%s", gnc_numeric_to_string (split->amount));
split->gains |= GAINS_STATUS_VDIRTY;
lot = pcy->PolicyGetLot (pcy, split);

View File

@ -40,7 +40,7 @@
/** @file cap-gains.h
* @brief Utilities to Automatically Compute Capital Gains/Losses.
* @author Created by Linas Vepstas August 2003
* @author Copyright (c) 2003 Linas Vepstas <linas@linas.org>
* @author Copyright (c) 2003,2004 Linas Vepstas <linas@linas.org>
*/
#ifndef XACC_CAP_GAINS_H
@ -81,9 +81,15 @@ gboolean xaccAccountHasTrades (Account *);
* The sign comparison helps identify a lot that can be
* added to: usually, one wants to add splits to a lot so
* that the balance only decreases.
* If 'currency' is non-null, then this attempts to find
* a lot whose opening transaction has the same currency.
*/
GNCLot * xaccAccountFindEarliestOpenLot (Account *acc, gnc_numeric sign);
GNCLot * xaccAccountFindLatestOpenLot (Account *acc, gnc_numeric sign);
GNCLot * xaccAccountFindEarliestOpenLot (Account *acc,
gnc_numeric sign,
gnc_commodity *currency);
GNCLot * xaccAccountFindLatestOpenLot (Account *acc,
gnc_numeric sign,
gnc_commodity *currency);
/** The xaccAccountGetDefaultGainAccount() routine will return
* the account to which realized gains/losses may be posted.

View File

@ -109,7 +109,9 @@ donext:
static GNCLot *
FIFOPolicyGetLot (GNCPolicy *pcy, Split *split)
{
return xaccAccountFindEarliestOpenLot (split->acc, split->amount);
if (!split) return NULL;
return xaccAccountFindEarliestOpenLot (split->acc, split->amount,
split->parent->common_currency);
}
static Split *
@ -169,7 +171,9 @@ xaccGetFIFOPolicy (void)
static GNCLot *
LIFOPolicyGetLot (GNCPolicy *pcy, Split *split)
{
return xaccAccountFindLatestOpenLot (split->acc, split->amount);
if (!split) return NULL;
return xaccAccountFindLatestOpenLot (split->acc, split->amount,
split->parent->common_currency);
}
static Split *