Testcase+fix for commodity being reported more than once per account in balance

This commit is contained in:
Dmitry Astapov 2011-12-25 21:21:27 +00:00
parent 7ac9934b27
commit 7426e93ec6
2 changed files with 24 additions and 2 deletions

View File

@ -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. -- | Render one balance report line item as plain text.
accountsReportItemAsText :: ReportOpts -> [FormatString] -> AccountsReportItem -> [String] accountsReportItemAsText :: ReportOpts -> [FormatString] -> AccountsReportItem -> [String]
accountsReportItemAsText opts format (_, accountName, depth, Mixed amounts) = 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] [a] -> [formatAccountsReportItem opts (Just accountName) depth a format]
(as) -> multiline as (as) -> multiline as

View File

@ -1,4 +1,4 @@
# this should balance # 1. this should balance
bin/hledger -f - print bin/hledger -f - print
<<< <<<
2011/1/1 2011/1/1
@ -7,3 +7,21 @@ bin/hledger -f - print
c $-30 c $-30
>>>2 !/could not balance/ >>>2 !/could not balance/
>>>= 0 >>>= 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