when we fail because of more than one missing amount in an entry, show the full entry

This commit is contained in:
Simon Michael 2008-10-16 03:56:43 +00:00
parent 0eb56821e9
commit 9acf11de4d
2 changed files with 12 additions and 5 deletions

View File

@ -26,8 +26,13 @@ isEntryBalanced (Entry {etransactions=ts}) = isZeroAmount sum && numcommodities=
sum = sumLedgerTransactions ts
numcommodities = length $ nub $ map (symbol . commodity . tamount) ts
-- | Fill in a missing balance in this entry, if there is one,
-- or raise an error if there is more than one.
autofillEntry :: Entry -> Entry
autofillEntry e@(Entry {etransactions=ts}) = e{etransactions=autofillTransactions ts}
autofillEntry e@(Entry {etransactions=ts}) = e{etransactions=ts'}
where ts' = fromMaybe
(error $ "too many blank transactions in this entry:\n" ++ show e)
(autofillTransactions ts)
assertBalancedEntry :: Entry -> Entry
assertBalancedEntry e

View File

@ -21,12 +21,14 @@ showRawTransaction t = (showaccountname $ taccount t) ++ " " ++ (showamount $ ta
showaccountname = printf "%-22s" . elideAccountName 22
showamount = printf "%12s" . showAmountOrZero
autofillTransactions :: [RawTransaction] -> [RawTransaction]
-- | Fill in the missing balance in an entry's transactions. There can be
-- at most one missing balance, otherwise we'll return Nothing.
autofillTransactions :: [RawTransaction] -> Maybe [RawTransaction]
autofillTransactions ts =
case (length blanks) of
0 -> ts
1 -> map balance ts
otherwise -> error "too many blank transactions in this entry"
0 -> Just ts
1 -> Just $ map balance ts
otherwise -> Nothing
where
(normals, blanks) = partition isnormal ts
isnormal t = (symbol $ commodity $ tamount t) /= "AUTO"