From 040d00e8fb4b6a107646549b1939bde98ea7cded Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 9 Aug 2015 15:12:16 -0700 Subject: [PATCH] also canonicalise historical price amounts So that when we convert amounts to market value, the result will have the canonical style of the target commodity. --- hledger-lib/Hledger/Data/Journal.hs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index 97f9feffb..b55c7ce4e 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -487,17 +487,19 @@ journalBalanceTransactions j@Journal{jtxns=ts, jcommoditystyles=ss} = Left e -> Left e where balance = balanceTransaction (Just ss) --- | Convert all the journal's posting amounts (not price amounts) to --- their canonical display settings. Ie, all amounts in a given --- commodity will use (a) the display settings of the first, and (b) --- the greatest precision, of the posting amounts in that commodity. +-- | Convert all the journal's posting amounts (and historical price +-- amounts, but currently not transaction price amounts) to their +-- canonical display settings. Ie, all amounts in a given commodity +-- will use (a) the display settings of the first, and (b) the +-- greatest precision, of the posting amounts in that commodity. journalCanonicaliseAmounts :: Journal -> Journal -journalCanonicaliseAmounts j@Journal{jtxns=ts} = j'' +journalCanonicaliseAmounts j@Journal{jtxns=ts, historical_prices=hps} = j'' where - j'' = j'{jtxns=map fixtransaction ts} + j'' = j'{jtxns=map fixtransaction ts, historical_prices=map fixhistoricalprice hps} j' = j{jcommoditystyles = canonicalStyles $ dbg8 "journalAmounts" $ journalAmounts j} fixtransaction t@Transaction{tpostings=ps} = t{tpostings=map fixposting ps} fixposting p@Posting{pamount=a} = p{pamount=fixmixedamount a} + fixhistoricalprice hp@HistoricalPrice{hamount=a} = hp{hamount=fixamount a} fixmixedamount (Mixed as) = Mixed $ map fixamount as fixamount a@Amount{acommodity=c} = a{astyle=journalCommodityStyle j' c}