clarify entry balance checking and show the full entry when unbalanced

This commit is contained in:
Simon Michael 2008-10-15 06:47:47 +00:00
parent 9f341b0279
commit 3138046744
2 changed files with 7 additions and 6 deletions

View File

@ -42,11 +42,12 @@ isEntryBalanced :: Entry -> Bool
isEntryBalanced = isZeroAmount . sumLedgerTransactions . etransactions
autofillEntry :: Entry -> Entry
autofillEntry e@(Entry _ _ _ _ _ ts _) =
let e' = e{etransactions=autofillTransactions ts} in
case (isEntryBalanced e') of
True -> e'
False -> (error $ "transactions don't balance in " ++ show e)
autofillEntry e@(Entry {etransactions=ts}) = e{etransactions=autofillTransactions ts}
assertBalancedEntry :: Entry -> Entry
assertBalancedEntry e
| isEntryBalanced e = e
| otherwise = error $ "transactions don't balance in:\n" ++ show e
{-|
Helper for the print command which shows cleaned up ledger file

View File

@ -231,7 +231,7 @@ ledgerentry = do
comment <- ledgercomment
restofline
transactions <- ledgertransactions
return $ autofillEntry $ Entry date status code description comment transactions (unlines preceding)
return $ assertBalancedEntry $ autofillEntry $ Entry date status code description comment transactions (unlines preceding)
ledgerdate :: Parser String
ledgerdate = do