diff --git a/hledger/Hledger/Cli/Commands/Roi.hs b/hledger/Hledger/Cli/Commands/Roi.hs index b1f278ad6..9bee351d9 100644 --- a/hledger/Hledger/Cli/Commands/Roi.hs +++ b/hledger/Hledger/Cli/Commands/Roi.hs @@ -263,6 +263,6 @@ total trans query = unMix $ sumPostings $ filter (matchesPosting query) $ conca unMix :: MixedAmount -> Quantity unMix a = - case (normaliseMixedAmount $ mixedAmountCost a) of - (Mixed [a]) -> aquantity a - _ -> error' "MixedAmount failed to normalize" -- PARTIAL: + case (unifyMixedAmount $ mixedAmountCost a) of + Just a -> aquantity a + Nothing -> error' $ "Amounts could not be converted to a single cost basis: " ++ show (map showAmount $ amounts a) diff --git a/hledger/test/roi.test b/hledger/test/roi.test index 9b9c7242f..0fd8e4ef2 100644 --- a/hledger/test/roi.test +++ b/hledger/test/roi.test @@ -225,3 +225,18 @@ hledger -f- roi -p 2019-11 +---++------------+------------++---------------+----------+-------------+-----++-------+-------+ >>>=0 + +# 9. Fail with a nice error message when commodity can't be valued +hledger -f- roi -p 2019-11 --inv Investment --pnl PnL +<<< +2019/11/01 Example + Assets:Checking -1 A + Investment 10 B + +2019/11/02 Example + Investment -10 B @@ 1 A + Assets:Checking 12 A + Unrealized PnL +>>>2 +hledger: Amounts could not be converted to a single cost basis: ["10 B","-10 B @@ 1 A"] +>>>=1