From dc16451de0e7a519356653ce88b23a0176d0f202 Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Fri, 7 May 2021 21:56:48 +1000 Subject: [PATCH] lib: Remove unused (amount|mixedAmount|posting|transaction)ApplyCostValuation functions. --- hledger-lib/Hledger/Data/Posting.hs | 9 ------- hledger-lib/Hledger/Data/Transaction.hs | 10 +------- hledger-lib/Hledger/Data/Valuation.hs | 33 +++++++------------------ hledger/Hledger/Cli/Commands/Roi.hs | 5 +++- 4 files changed, 14 insertions(+), 43 deletions(-) diff --git a/hledger-lib/Hledger/Data/Posting.hs b/hledger-lib/Hledger/Data/Posting.hs index 778e6c967..54c1d8f4a 100644 --- a/hledger-lib/Hledger/Data/Posting.hs +++ b/hledger-lib/Hledger/Data/Posting.hs @@ -64,7 +64,6 @@ module Hledger.Data.Posting ( -- * misc. showComment, postingTransformAmount, - postingApplyCostValuation, postingApplyValuation, postingToCost, tests_Posting @@ -332,14 +331,6 @@ aliasReplace (BasicAlias old new) a aliasReplace (RegexAlias re repl) a = fmap T.pack . regexReplace re repl $ T.unpack a -- XXX --- | Apply a specified costing and valuation to this posting's amount, --- using the provided price oracle, commodity styles, and reference dates. --- Costing is done first if requested, and after that any valuation. --- See amountApplyValuation and amountCost. -postingApplyCostValuation :: PriceOracle -> M.Map CommoditySymbol AmountStyle -> Day -> Day -> Costing -> Maybe ValuationType -> Posting -> Posting -postingApplyCostValuation priceoracle styles periodlast today cost v p = - postingTransformAmount (mixedAmountApplyCostValuation priceoracle styles periodlast today (postingDate p) cost v) p - -- | Apply a specified valuation to this posting's amount, using the -- provided price oracle, commodity styles, and reference dates. -- See amountApplyValuation. diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index 54e9d93c5..9f80c8ba0 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -33,7 +33,6 @@ module Hledger.Data.Transaction ( balanceTransaction, balanceTransactionHelper, transactionTransformPostings, - transactionApplyCostValuation, transactionApplyValuation, transactionToCost, transactionApplyAliases, @@ -615,13 +614,6 @@ postingSetTransaction t p = p{ptransaction=Just t} transactionTransformPostings :: (Posting -> Posting) -> Transaction -> Transaction transactionTransformPostings f t@Transaction{tpostings=ps} = t{tpostings=map f ps} --- | Apply a specified costing and valuation to this transaction's amounts, --- using the provided price oracle, commodity styles, and reference dates. --- See amountApplyValuation and amountCost. -transactionApplyCostValuation :: PriceOracle -> M.Map CommoditySymbol AmountStyle -> Day -> Day -> Costing -> Maybe ValuationType -> Transaction -> Transaction -transactionApplyCostValuation priceoracle styles periodlast today cost v = - transactionTransformPostings (postingApplyCostValuation priceoracle styles periodlast today cost v) - -- | Apply a specified valuation to this transaction's amounts, using -- the provided price oracle, commodity styles, and reference dates. -- See amountApplyValuation. @@ -631,7 +623,7 @@ transactionApplyValuation priceoracle styles periodlast today v = -- | Convert this transaction's amounts to cost, and apply the appropriate amount styles. transactionToCost :: M.Map CommoditySymbol AmountStyle -> Transaction -> Transaction -transactionToCost styles t@Transaction{tpostings=ps} = t{tpostings=map (postingToCost styles) ps} +transactionToCost styles = transactionTransformPostings (postingToCost styles) -- | Apply some account aliases to all posting account names in the transaction, as described by accountNameApplyAliases. -- This can fail due to a bad replacement pattern in a regular expression alias. diff --git a/hledger-lib/Hledger/Data/Valuation.hs b/hledger-lib/Hledger/Data/Valuation.hs index c95b79130..7b301d2b3 100644 --- a/hledger-lib/Hledger/Data/Valuation.hs +++ b/hledger-lib/Hledger/Data/Valuation.hs @@ -17,10 +17,7 @@ module Hledger.Data.Valuation ( ,ValuationType(..) ,PriceOracle ,journalPriceOracle - ,amountApplyCostValuation - ,amountApplyValuation - ,amountValueAtDate - ,mixedAmountApplyCostValuation + ,mixedAmountToCost ,mixedAmountApplyValuation ,mixedAmountValueAtDate ,marketPriceReverse @@ -100,13 +97,9 @@ priceDirectiveToMarketPrice PriceDirective{..} = ------------------------------------------------------------------------------ -- Converting things to value --- | Apply a specified costing and valuation to this mixed amount, --- using the provided price oracle, commodity styles, and reference dates. --- Costing is done first if requested, and after that any valuation. --- See amountApplyValuation and amountCost. -mixedAmountApplyCostValuation :: PriceOracle -> M.Map CommoditySymbol AmountStyle -> Day -> Day -> Day -> Costing -> Maybe ValuationType -> MixedAmount -> MixedAmount -mixedAmountApplyCostValuation priceoracle styles periodlast today postingdate cost v = - mapMixedAmount (amountApplyCostValuation priceoracle styles periodlast today postingdate cost v) +-- | Convert all component amounts to cost/selling price if requested, and style them. +mixedAmountToCost :: Costing -> M.Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount +mixedAmountToCost cost styles = mapMixedAmount (amountToCost cost styles) -- | Apply a specified valuation to this mixed amount, using the -- provided price oracle, commodity styles, and reference dates. @@ -115,18 +108,10 @@ mixedAmountApplyValuation :: PriceOracle -> M.Map CommoditySymbol AmountStyle -> mixedAmountApplyValuation priceoracle styles periodlast today postingdate v = mapMixedAmount (amountApplyValuation priceoracle styles periodlast today postingdate v) --- | Apply a specified costing and valuation to this Amount, --- using the provided price oracle, commodity styles, and reference dates. --- Costing is done first if requested, and after that any valuation. --- See amountApplyValuation and amountCost. -amountApplyCostValuation :: PriceOracle -> M.Map CommoditySymbol AmountStyle -> Day -> Day -> Day -> Costing -> Maybe ValuationType -> Amount -> Amount -amountApplyCostValuation priceoracle styles periodlast today postingdate cost v = - valuation . costing - where - valuation = maybe id (amountApplyValuation priceoracle styles periodlast today postingdate) v - costing = case cost of - Cost -> styleAmount styles . amountCost - NoCost -> id +-- | Convert an Amount to its cost if requested, and style it appropriately. +amountToCost :: Costing -> M.Map CommoditySymbol AmountStyle -> Amount -> Amount +amountToCost NoCost _ = id +amountToCost Cost styles = styleAmount styles . amountCost -- | Apply a specified valuation to this amount, using the provided -- price oracle, reference dates, and whether this is for a @@ -151,7 +136,7 @@ amountApplyCostValuation priceoracle styles periodlast today postingdate cost v -- -- - the provided "today" date - (--value=now, or -V/X with no report -- end date). --- +-- -- This is all a bit complicated. See the reference doc at -- https://hledger.org/hledger.html#effect-of-valuation-on-reports -- (hledger_options.m4.md "Effect of valuation on reports"), and #1083. diff --git a/hledger/Hledger/Cli/Commands/Roi.hs b/hledger/Hledger/Cli/Commands/Roi.hs index b32c3869b..643674a7c 100644 --- a/hledger/Hledger/Cli/Commands/Roi.hs +++ b/hledger/Hledger/Cli/Commands/Roi.hs @@ -63,7 +63,10 @@ roi CliOpts{rawopts_=rawopts, reportspec_=rspec@ReportSpec{rsOpts=ReportOpts{..} priceOracle = journalPriceOracle infer_value_ j styles = journalCommodityStyles j today = rsToday rspec - mixedAmountValue periodlast date = mixedAmountApplyCostValuation priceOracle styles periodlast today date cost_ value_ + mixedAmountValue periodlast date = + maybe id (mixedAmountApplyValuation priceOracle styles periodlast today date) value_ + . mixedAmountToCost cost_ styles + let ropts = rsOpts rspec showCashFlow = boolopt "cashflow" rawopts