rename setAmountDisplayPrefs to canonicaliseAmounts

This commit is contained in:
Simon Michael 2008-11-08 22:02:38 +00:00
parent 514f015849
commit ea5a87815b
3 changed files with 7 additions and 7 deletions

View File

@ -81,11 +81,11 @@ filterRawLedgerTransactionsByRealness True (RawLedger ms ps es f) =
where filtertxns e@Entry{etransactions=ts} = e{etransactions=filter isReal ts}
-- | Give all a ledger's amounts their canonical display settings. That
-- is, in each commodity all amounts will use the display settings of the
-- first amount detected, and the greatest precision of all amounts
-- is, in each commodity, amounts will use the display settings of the
-- first amount detected, and the greatest precision of the amounts
-- detected.
setAmountDisplayPrefs :: RawLedger -> RawLedger
setAmountDisplayPrefs l@(RawLedger ms ps es f) = RawLedger ms ps (map fixEntryAmounts es) f
canonicaliseAmounts :: RawLedger -> RawLedger
canonicaliseAmounts l@(RawLedger ms ps es f) = RawLedger ms ps (map fixEntryAmounts es) f
where
fixEntryAmounts (Entry d s c de co ts pr) = Entry d s c de co (map fixRawTransactionAmounts ts) pr
fixRawTransactionAmounts (RawTransaction ac a c t) = RawTransaction ac (fixMixedAmount a) c t

View File

@ -87,8 +87,8 @@ misc_tests = TestList [
assertparseequal (Mixed [dollars 47.18]) (parsewith transactionamount " $47.18")
assertparseequal (Mixed [Amount (Commodity {symbol="$",side=L,spaced=False,comma=False,precision=0}) 1 Nothing]) (parsewith transactionamount " $1.")
,
"setAmountDisplayPrefs" ~: do
let l = setAmountDisplayPrefs $ rawLedgerWithAmounts ["1","2.00"]
"canonicaliseAmounts" ~: do
let l = canonicaliseAmounts $ rawLedgerWithAmounts ["1","2.00"]
assertequal [2,2] (rawLedgerPrecisions l) -- use greatest precision everywhere
] where

View File

@ -73,7 +73,7 @@ parseLedgerAndDo :: [Opt] -> [String] -> ([Opt] -> [String] -> Ledger -> IO ())
parseLedgerAndDo opts args cmd =
ledgerFilePathFromOpts opts >>= parseLedgerFile >>= either printParseError runcmd
where
runcmd = cmd opts args . cacheLedger . setAmountDisplayPrefs . filterRawLedger b e dpats c r
runcmd = cmd opts args . cacheLedger . canonicaliseAmounts . filterRawLedger b e dpats c r
b = parsemaybedate (beginDateFromOpts opts)
e = parsemaybedate (endDateFromOpts opts)
dpats = snd $ parseAccountDescriptionArgs args