dev: no need to style amounts when converting to cost
This commit is contained in:
parent
c215f920aa
commit
d8a3c9fa3e
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user