diff --git a/hledger/Hledger/Cli/Balance.hs b/hledger/Hledger/Cli/Balance.hs index e7d76b074..584e6c9d7 100644 --- a/hledger/Hledger/Cli/Balance.hs +++ b/hledger/Hledger/Cli/Balance.hs @@ -147,7 +147,11 @@ This implementation turned out to be a bit convoluted but implements the followi -- | Render one balance report line item as plain text. accountsReportItemAsText :: ReportOpts -> [FormatString] -> AccountsReportItem -> [String] accountsReportItemAsText opts format (_, accountName, depth, Mixed amounts) = - case amounts of + -- 'amounts' could contain several quantities of the same commodity with different price. + -- In order to combine them into single value (which is expected) we take the first price and + -- use it for the whole mixed amount. This could be suboptimal. XXX + let Mixed normAmounts = normaliseMixedAmount (Mixed amounts) in + case normAmounts of [] -> [] [a] -> [formatAccountsReportItem opts (Just accountName) depth a format] (as) -> multiline as diff --git a/tests/balancing-with-prices.test b/tests/balancing-with-prices.test index 4a76d6293..0a0cdc3a5 100644 --- a/tests/balancing-with-prices.test +++ b/tests/balancing-with-prices.test @@ -1,4 +1,4 @@ -# this should balance +# 1. this should balance bin/hledger -f - print <<< 2011/1/1 @@ -7,3 +7,21 @@ bin/hledger -f - print c $-30 >>>2 !/could not balance/ >>>= 0 +# 2. When commodity price is specified for the whole transaction, it should still be reported +# in the balance as a single quantity even when prices change over time +bin/hledger -f - balance +<<< +2011/01/01 conv1 + expenses 10£ @@ 16$ + cash -16$ + +2011/01/02 conv2 + expenses 10£ @@ 15$ + cash -15$ +>>> + -31$ cash + 20£ expenses +-------------------- + -31$ + 20£ +>>>=0