diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index 5debb5e26..28d8be8d3 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 356c77aaa..1f2e2c90d 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 aebddef8d..0fc417200 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 diff --git a/hledger-ui/Hledger/UI/TransactionScreen.hs b/hledger-ui/Hledger/UI/TransactionScreen.hs index bfe550f04..1cc94de8f 100644 --- a/hledger-ui/Hledger/UI/TransactionScreen.hs +++ b/hledger-ui/Hledger/UI/TransactionScreen.hs @@ -102,7 +102,7 @@ showTxn :: ReportOpts -> ReportSpec -> Journal -> Transaction -> T.Text showTxn ropts rspec j t = showTransactionOneLineAmounts $ maybe id (transactionApplyValuation prices styles periodlast (_rsDay rspec)) (value_ ropts) - $ maybe id (transactionToCost styles) (conversionop_ ropts) t + $ maybe id transactionToCost (conversionop_ ropts) t -- (if real_ ropts then filterTransactionPostings (Real True) else id) -- filter postings by --real where prices = journalPriceOracle (infer_prices_ ropts) j