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
|
journalPostings j
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Convert all this journal's amounts to cost using the transaction prices, if any.
|
-- | Convert all this journal's amounts to cost using their attached prices, if any.
|
||||||
-- The journal's commodity styles are applied to the resulting amounts.
|
|
||||||
journalToCost :: ConversionOp -> Journal -> Journal
|
journalToCost :: ConversionOp -> Journal -> Journal
|
||||||
journalToCost cost j@Journal{jtxns=ts} = j{jtxns=map (transactionToCost styles cost) ts}
|
journalToCost cost j@Journal{jtxns=ts} = j{jtxns=map (transactionToCost cost) ts}
|
||||||
where
|
|
||||||
styles = journalCommodityStyles j
|
|
||||||
|
|
||||||
-- | Add equity postings inferred from costs, where needed and possible.
|
-- | Add equity postings inferred from costs, where needed and possible.
|
||||||
-- See hledger manual > Cost reporting.
|
-- See hledger manual > Cost reporting.
|
||||||
|
|||||||
@ -447,14 +447,13 @@ postingApplyValuation :: PriceOracle -> M.Map CommoditySymbol AmountStyle -> Day
|
|||||||
postingApplyValuation priceoracle styles periodlast today v p =
|
postingApplyValuation priceoracle styles periodlast today v p =
|
||||||
postingTransformAmount (mixedAmountApplyValuation priceoracle styles periodlast today (postingDate p) v) p
|
postingTransformAmount (mixedAmountApplyValuation priceoracle styles periodlast today (postingDate p) v) p
|
||||||
|
|
||||||
-- | Maybe convert this 'Posting's amount to cost, and apply apply appropriate
|
-- | Maybe convert this 'Posting's amount to cost.
|
||||||
-- amount styles.
|
postingToCost :: ConversionOp -> Posting -> Maybe Posting
|
||||||
postingToCost :: M.Map CommoditySymbol AmountStyle -> ConversionOp -> Posting -> Maybe Posting
|
postingToCost NoConversionOp p = Just p
|
||||||
postingToCost _ NoConversionOp p = Just p
|
postingToCost ToCost p
|
||||||
postingToCost styles ToCost p
|
|
||||||
-- If this is a conversion posting with a matched transaction price posting, ignore it
|
-- If this is a conversion posting with a matched transaction price posting, ignore it
|
||||||
| "_conversion-matched" `elem` map fst (ptags p) && noCost = Nothing
|
| "_conversion-matched" `elem` map fst (ptags p) && noCost = Nothing
|
||||||
| otherwise = Just $ postingTransformAmount (mixedAmountSetStyles styles . mixedAmountCost) p
|
| otherwise = Just $ postingTransformAmount mixedAmountCost p
|
||||||
where
|
where
|
||||||
noCost = (not . any (isJust . aprice) . amountsRaw) $ pamount p
|
noCost = (not . any (isJust . aprice) . amountsRaw) $ pamount p
|
||||||
|
|
||||||
|
|||||||
@ -221,10 +221,9 @@ transactionApplyValuation :: PriceOracle -> M.Map CommoditySymbol AmountStyle ->
|
|||||||
transactionApplyValuation priceoracle styles periodlast today v =
|
transactionApplyValuation priceoracle styles periodlast today v =
|
||||||
transactionTransformPostings (postingApplyValuation priceoracle styles periodlast today v)
|
transactionTransformPostings (postingApplyValuation priceoracle styles periodlast today v)
|
||||||
|
|
||||||
-- | Maybe convert this 'Transaction's amounts to cost and apply the
|
-- | Maybe convert this 'Transaction's amounts to cost.
|
||||||
-- appropriate amount styles.
|
transactionToCost :: ConversionOp -> Transaction -> Transaction
|
||||||
transactionToCost :: M.Map CommoditySymbol AmountStyle -> ConversionOp -> Transaction -> Transaction
|
transactionToCost cost t = t{tpostings = mapMaybe (postingToCost cost) $ tpostings t}
|
||||||
transactionToCost styles cost t = t{tpostings = mapMaybe (postingToCost styles cost) $ tpostings t}
|
|
||||||
|
|
||||||
-- | Add inferred equity postings to a 'Transaction' using transaction prices.
|
-- | Add inferred equity postings to a 'Transaction' using transaction prices.
|
||||||
transactionAddInferredEquityPostings :: Bool -> AccountName -> Transaction -> Transaction
|
transactionAddInferredEquityPostings :: Bool -> AccountName -> Transaction -> Transaction
|
||||||
|
|||||||
@ -102,7 +102,7 @@ showTxn :: ReportOpts -> ReportSpec -> Journal -> Transaction -> T.Text
|
|||||||
showTxn ropts rspec j t =
|
showTxn ropts rspec j t =
|
||||||
showTransactionOneLineAmounts
|
showTransactionOneLineAmounts
|
||||||
$ maybe id (transactionApplyValuation prices styles periodlast (_rsDay rspec)) (value_ ropts)
|
$ 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
|
-- (if real_ ropts then filterTransactionPostings (Real True) else id) -- filter postings by --real
|
||||||
where
|
where
|
||||||
prices = journalPriceOracle (infer_prices_ ropts) j
|
prices = journalPriceOracle (infer_prices_ ropts) j
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user