fix reporting of unbalanced entries

This commit is contained in:
Simon Michael 2008-12-05 10:04:59 +00:00
parent 0f91583230
commit f69716ddf9
2 changed files with 11 additions and 8 deletions

View File

@ -71,15 +71,19 @@ showEntry e =
isEntryBalanced :: Entry -> Bool isEntryBalanced :: Entry -> Bool
isEntryBalanced (Entry {etransactions=ts}) = 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 -- | Ensure that this entry is balanced, possibly auto-filling a missing
-- information to do that. Excluding virtual transactions, there should be -- amount first. We can auto-fill if there is just one non-virtual
-- at most one missing balance. Otherwise, raise an error. -- transaction without an amount. The auto-filled balance will be
-- The new balance will be converted to cost basis if possible. -- converted to cost basis if possible. If the entry can not be balanced,
-- raise an error.
balanceEntry :: Entry -> Entry balanceEntry :: Entry -> Entry
balanceEntry e@Entry{etransactions=ts} = e{etransactions=ts'} balanceEntry e@Entry{etransactions=ts} = (e{etransactions=ts'})
where where
check e
| isEntryBalanced e = e
| otherwise = error $ "could not balance this entry:\n" ++ show e
(withamounts, missingamounts) = partition hasAmount $ filter isReal ts (withamounts, missingamounts) = partition hasAmount $ filter isReal ts
ts' = case (length missingamounts) of ts' = case (length missingamounts) of
0 -> ts 0 -> ts

1
NOTES
View File

@ -10,7 +10,6 @@ clever tricks like the plague." --Edsger Dijkstra
* to do * to do
** errors ** errors
*** does not catch an unbalanced entry
*** can't parse comment line immediately after or within an entry *** can't parse comment line immediately after or within an entry
*** depth-limited balance report may not show final total *** depth-limited balance report may not show final total
*** print does not always give tidy layout *** print does not always give tidy layout