From f69716ddf9d5f6b4037414a63d674effd338fdee Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 5 Dec 2008 10:04:59 +0000 Subject: [PATCH] fix reporting of unbalanced entries --- Ledger/Entry.hs | 18 +++++++++++------- NOTES | 1 - 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Ledger/Entry.hs b/Ledger/Entry.hs index 87397d741..84dc32dec 100644 --- a/Ledger/Entry.hs +++ b/Ledger/Entry.hs @@ -71,15 +71,19 @@ showEntry e = isEntryBalanced :: Entry -> Bool isEntryBalanced (Entry {etransactions=ts}) = - isZeroMixedAmount $ sum $ map tamount $ filter isReal ts + isZeroMixedAmount $ costOfMixedAmount $ sum $ map tamount $ filter isReal ts --- | Fill in a missing balance in this entry, if we have enough --- information to do that. Excluding virtual transactions, there should be --- at most one missing balance. Otherwise, raise an error. --- The new balance will be converted to cost basis if possible. +-- | Ensure that this entry is balanced, possibly auto-filling a missing +-- amount first. We can auto-fill if there is just one non-virtual +-- transaction without an amount. The auto-filled balance will be +-- converted to cost basis if possible. If the entry can not be balanced, +-- raise an error. balanceEntry :: Entry -> Entry -balanceEntry e@Entry{etransactions=ts} = e{etransactions=ts'} - where +balanceEntry e@Entry{etransactions=ts} = (e{etransactions=ts'}) + where + check e + | isEntryBalanced e = e + | otherwise = error $ "could not balance this entry:\n" ++ show e (withamounts, missingamounts) = partition hasAmount $ filter isReal ts ts' = case (length missingamounts) of 0 -> ts diff --git a/NOTES b/NOTES index 2f9078e78..33b149963 100644 --- a/NOTES +++ b/NOTES @@ -10,7 +10,6 @@ clever tricks like the plague." --Edsger Dijkstra * to do ** errors -*** does not catch an unbalanced entry *** can't parse comment line immediately after or within an entry *** depth-limited balance report may not show final total *** print does not always give tidy layout