mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 15:14:49 +03:00
when we fail because of more than one missing amount in an entry, show the full entry
This commit is contained in:
parent
0eb56821e9
commit
9acf11de4d
@ -26,8 +26,13 @@ isEntryBalanced (Entry {etransactions=ts}) = isZeroAmount sum && numcommodities=
|
|||||||
sum = sumLedgerTransactions ts
|
sum = sumLedgerTransactions ts
|
||||||
numcommodities = length $ nub $ map (symbol . commodity . tamount) 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 :: 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 :: Entry -> Entry
|
||||||
assertBalancedEntry e
|
assertBalancedEntry e
|
||||||
|
@ -21,12 +21,14 @@ showRawTransaction t = (showaccountname $ taccount t) ++ " " ++ (showamount $ ta
|
|||||||
showaccountname = printf "%-22s" . elideAccountName 22
|
showaccountname = printf "%-22s" . elideAccountName 22
|
||||||
showamount = printf "%12s" . showAmountOrZero
|
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 =
|
autofillTransactions ts =
|
||||||
case (length blanks) of
|
case (length blanks) of
|
||||||
0 -> ts
|
0 -> Just ts
|
||||||
1 -> map balance ts
|
1 -> Just $ map balance ts
|
||||||
otherwise -> error "too many blank transactions in this entry"
|
otherwise -> Nothing
|
||||||
where
|
where
|
||||||
(normals, blanks) = partition isnormal ts
|
(normals, blanks) = partition isnormal ts
|
||||||
isnormal t = (symbol $ commodity $ tamount t) /= "AUTO"
|
isnormal t = (symbol $ commodity $ tamount t) /= "AUTO"
|
||||||
|
Loading…
Reference in New Issue
Block a user