more balance/amount clarifications and a test
This commit is contained in:
parent
9aaf489a38
commit
1273f02a9a
@ -109,6 +109,7 @@ instance Num MixedAmount where
|
||||
negate (Mixed as) = Mixed $ map negateAmountPreservingPrice as
|
||||
where negateAmountPreservingPrice a = (-a){price=price a}
|
||||
(+) (Mixed as) (Mixed bs) = normaliseMixedAmount $ Mixed $ as ++ bs
|
||||
-- (+) (Mixed as) (Mixed bs) = normaliseMixedAmountPreservingHighestPrecision $ Mixed $ as ++ bs
|
||||
(*) = error' "programming error, mixed amounts do not support multiplication"
|
||||
abs = error' "programming error, mixed amounts do not support abs"
|
||||
signum = error' "programming error, mixed amounts do not support signum"
|
||||
|
||||
@ -415,6 +415,10 @@ postingsByAccount ps = m'
|
||||
groupedps = groupBy (\p1 p2 -> paccount p1 == paccount p2) sortedps
|
||||
m' = Map.fromList [(paccount $ head g, g) | g <- groupedps]
|
||||
|
||||
-- debug helpers
|
||||
traceAmountPrecision a = trace (show $ map (precision . commodity) $ amounts a) a
|
||||
tracePostingsCommodities ps = trace (show $ map ((map (precision . commodity) . amounts) . pamount) ps) ps
|
||||
|
||||
tests_Hledger_Data_Journal = TestList [
|
||||
]
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ import Hledger.Data.Types
|
||||
import Hledger.Utils
|
||||
import Hledger.Data.Posting
|
||||
import Hledger.Data.Dates (getCurrentYear)
|
||||
import Hledger.Data.Journal (nullctx, nulljournal, journalFinalise)
|
||||
import Hledger.Data.Journal
|
||||
|
||||
|
||||
juSequence :: [JournalUpdate] -> JournalUpdate
|
||||
|
||||
@ -153,32 +153,30 @@ accountsReportItemAsText opts format (_, accountName, depth, Mixed amounts) =
|
||||
case amounts of
|
||||
[] -> []
|
||||
[a] -> [formatAccountsReportItem opts (Just accountName) depth a format]
|
||||
(as) -> asText as
|
||||
(as) -> multiline as
|
||||
where
|
||||
asText :: [Amount] -> [String]
|
||||
asText [] = []
|
||||
asText [a] = [formatAccountsReportItem opts (Just accountName) depth a format]
|
||||
asText (a:as) = (formatAccountsReportItem opts Nothing depth a format) : asText as
|
||||
multiline :: [Amount] -> [String]
|
||||
multiline [] = []
|
||||
multiline [a] = [formatAccountsReportItem opts (Just accountName) depth a format]
|
||||
multiline (a:as) = (formatAccountsReportItem opts Nothing depth a format) : multiline as
|
||||
|
||||
formatAccountsReportItem :: ReportOpts -> Maybe AccountName -> Int -> Amount -> [FormatString] -> String
|
||||
formatAccountsReportItem _ _ _ _ [] = ""
|
||||
formatAccountsReportItem opts accountName depth amount (fmt:fmts) =
|
||||
s ++ (formatAccountsReportItem opts accountName depth amount fs)
|
||||
s ++ (formatAccountsReportItem opts accountName depth amount fmts)
|
||||
where
|
||||
s = case fmt of
|
||||
FormatLiteral l -> l
|
||||
FormatField ljust min max field -> formatField opts accountName depth amount ljust min max field
|
||||
|
||||
formatField :: ReportOpts -> Maybe AccountName -> Int -> Amount -> Bool -> Maybe Int -> Maybe Int -> Field -> String
|
||||
formatField opts accountName depth balance ljust min max field = case field of
|
||||
Format.Account -> formatValue ljust min max a
|
||||
formatField opts accountName depth total ljust min max field = case field of
|
||||
Format.Account -> formatValue ljust min max $ maybe "" (accountNameDrop (drop_ opts)) accountName
|
||||
Format.DepthSpacer -> case min of
|
||||
Just m -> formatValue ljust Nothing max $ replicate (depth * m) ' '
|
||||
Nothing -> formatValue ljust Nothing max $ replicate depth ' '
|
||||
Format.Total -> formatValue ljust min max $ showAmountWithoutPrice balance
|
||||
Format.Total -> formatValue ljust min max $ showAmountWithoutPrice total
|
||||
_ -> ""
|
||||
where
|
||||
a = maybe "" (accountNameDrop (drop_ opts)) accountName
|
||||
|
||||
tests_Hledger_Cli_Balance = TestList
|
||||
[
|
||||
|
||||
12
tests/balance-precision.test
Normal file
12
tests/balance-precision.test
Normal file
@ -0,0 +1,12 @@
|
||||
#
|
||||
bin/hledger -f- bal
|
||||
<<<
|
||||
1/1
|
||||
a 1.00
|
||||
b -1
|
||||
>>>
|
||||
1.00 a
|
||||
-1.00 b
|
||||
--------------------
|
||||
0
|
||||
>>>=0
|
||||
Loading…
Reference in New Issue
Block a user