Widen the scope of the subsplit merge scrub function

When used in a strict sense it will only merge splits
that are marked as subsplits of each other.
In relaxed mode it will merge any split two splits that
are both in the same lot and the same transaction.
This commit is contained in:
Geert Janssens 2014-08-23 15:20:13 +02:00
parent da9071fe49
commit 413eb69707
3 changed files with 18 additions and 11 deletions

View File

@ -344,7 +344,7 @@ merge_splits (Split *sa, Split *sb)
}
gboolean
xaccScrubMergeSubSplits (Split *split)
xaccScrubMergeSubSplits (Split *split, gboolean strict)
{
gboolean rc = FALSE;
Transaction *txn;
@ -352,7 +352,7 @@ xaccScrubMergeSubSplits (Split *split)
GNCLot *lot;
const GncGUID *guid;
if (FALSE == is_subsplit (split)) return FALSE;
if (strict && (FALSE == is_subsplit (split))) return FALSE;
txn = split->parent;
lot = xaccSplitGetLot (split);
@ -392,7 +392,7 @@ restart:
}
gboolean
xaccScrubMergeLotSubSplits (GNCLot *lot)
xaccScrubMergeLotSubSplits (GNCLot *lot, gboolean strict)
{
gboolean rc = FALSE;
SplitList *node;
@ -404,7 +404,7 @@ restart:
for (node = gnc_lot_get_split_list(lot); node; node = node->next)
{
Split *s = node->data;
if (!xaccScrubMergeSubSplits(s)) continue;
if (!xaccScrubMergeSubSplits(s, strict)) continue;
rc = TRUE;
goto restart;

View File

@ -89,19 +89,26 @@ void xaccLotScrubDoubleBalance (GNCLot *lot);
* the same lot, or in no lot. Note that, by definition, all
* subsplits belong to the same transaction.
*
* There are two ways to find matching subsplits. The first
* way will consider splits to be subsplits only if they
* are explicitly marked as such while splitting the original
* split. Set strict to TRUE for this matching algorhythm.
*
* The second way is more relaxed. It will consider any two
* splits that happen to be part of the same lot and the
* same transaction to be subsplits. Set strict to FALSE for
* this matching algorhythm.
*
* The routine returns TRUE if a merger was performed, else
* it returns FALSE.
*
* The xaccScrubMergeTransSubSplits() routine does the same, except
* that it does it for all of the splits in the transaction.
*/
gboolean xaccScrubMergeSubSplits (Split *split);
gboolean xaccScrubMergeSubSplits (Split *split, gboolean strict);
/** The xaccScrubMergeLotSubSplits() routine does the same as
* the xaccScrubMergSubSplits, except that it does it
* for all of the splits in the lot.
*/
gboolean xaccScrubMergeLotSubSplits (GNCLot *lot);
gboolean xaccScrubMergeLotSubSplits (GNCLot *lot, gboolean strict);
#endif /* XACC_SCRUB2_H */
/** @} */

View File

@ -96,7 +96,7 @@ xaccScrubLot (GNCLot *lot)
acc = gnc_lot_get_account (lot);
pcy = gnc_account_get_policy(acc);
xaccAccountBeginEdit(acc);
xaccScrubMergeLotSubSplits (lot);
xaccScrubMergeLotSubSplits (lot, TRUE);
/* If the lot balance is zero, we don't need to rebalance */
lot_baln = gnc_lot_get_balance (lot);
@ -132,7 +132,7 @@ rethin:
xaccLotFill (lot);
/* Make sure there are no subsplits. */
splits_deleted = xaccScrubMergeLotSubSplits (lot);
splits_deleted = xaccScrubMergeLotSubSplits (lot, TRUE);
}
/* Now re-compute cap gains, and then double-check that.