diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index 48b67d0ba..758835403 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -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" diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index e53b2feb0..21cb032ca 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -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 [ ] diff --git a/hledger-lib/Hledger/Read/Utils.hs b/hledger-lib/Hledger/Read/Utils.hs index 34a1477b7..3a0aa20f2 100644 --- a/hledger-lib/Hledger/Read/Utils.hs +++ b/hledger-lib/Hledger/Read/Utils.hs @@ -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 diff --git a/hledger/Hledger/Cli/Balance.hs b/hledger/Hledger/Cli/Balance.hs index 297183ac5..aaa6150b8 100644 --- a/hledger/Hledger/Cli/Balance.hs +++ b/hledger/Hledger/Cli/Balance.hs @@ -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 [ diff --git a/tests/balance-precision.test b/tests/balance-precision.test new file mode 100644 index 000000000..848961d59 --- /dev/null +++ b/tests/balance-precision.test @@ -0,0 +1,12 @@ +# +bin/hledger -f- bal +<<< +1/1 + a 1.00 + b -1 +>>> + 1.00 a + -1.00 b +-------------------- + 0 +>>>=0