diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index 5debb5e26d08..28d8be8d31fa 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -909,12 +909,9 @@ journalInferMarketPricesFromTransactions j = journalPostings j } --- | Convert all this journal's amounts to cost using the transaction prices, if any. --- The journal's commodity styles are applied to the resulting amounts. +-- | Convert all this journal's amounts to cost using their attached prices, if any. journalToCost :: ConversionOp -> Journal -> Journal -journalToCost cost j@Journal{jtxns=ts} = j{jtxns=map (transactionToCost styles cost) ts} - where - styles = journalCommodityStyles j +journalToCost cost j@Journal{jtxns=ts} = j{jtxns=map (transactionToCost cost) ts} -- | Add equity postings inferred from costs, where needed and possible. -- See hledger manual > Cost reporting. diff --git a/hledger-lib/Hledger/Data/Posting.hs b/hledger-lib/Hledger/Data/Posting.hs index 356c77aaa1ff..1f2e2c90d122 100644 --- a/hledger-lib/Hledger/Data/Posting.hs +++ b/hledger-lib/Hledger/Data/Posting.hs @@ -447,14 +447,13 @@ postingApplyValuation :: PriceOracle -> M.Map CommoditySymbol AmountStyle -> Day postingApplyValuation priceoracle styles periodlast today v p = postingTransformAmount (mixedAmountApplyValuation priceoracle styles periodlast today (postingDate p) v) p --- | Maybe convert this 'Posting's amount to cost, and apply apply appropriate --- amount styles. -postingToCost :: M.Map CommoditySymbol AmountStyle -> ConversionOp -> Posting -> Maybe Posting -postingToCost _ NoConversionOp p = Just p -postingToCost styles ToCost p +-- | Maybe convert this 'Posting's amount to cost. +postingToCost :: ConversionOp -> Posting -> Maybe Posting +postingToCost NoConversionOp p = Just p +postingToCost ToCost p -- If this is a conversion posting with a matched transaction price posting, ignore it | "_conversion-matched" `elem` map fst (ptags p) && noCost = Nothing - | otherwise = Just $ postingTransformAmount (mixedAmountSetStyles styles . mixedAmountCost) p + | otherwise = Just $ postingTransformAmount mixedAmountCost p where noCost = (not . any (isJust . aprice) . amountsRaw) $ pamount p diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index aebddef8df7f..0fc41720089a 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -221,10 +221,9 @@ transactionApplyValuation :: PriceOracle -> M.Map CommoditySymbol AmountStyle -> transactionApplyValuation priceoracle styles periodlast today v = transactionTransformPostings (postingApplyValuation priceoracle styles periodlast today v) --- | Maybe convert this 'Transaction's amounts to cost and apply the --- appropriate amount styles. -transactionToCost :: M.Map CommoditySymbol AmountStyle -> ConversionOp -> Transaction -> Transaction -transactionToCost styles cost t = t{tpostings = mapMaybe (postingToCost styles cost) $ tpostings t} +-- | Maybe convert this 'Transaction's amounts to cost. +transactionToCost :: ConversionOp -> Transaction -> Transaction +transactionToCost cost t = t{tpostings = mapMaybe (postingToCost cost) $ tpostings t} -- | Add inferred equity postings to a 'Transaction' using transaction prices. transactionAddInferredEquityPostings :: Bool -> AccountName -> Transaction -> Transaction