From e201775e93e8ae54b9ef9cc0a4ecbee4120d1f11 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 23 Jan 2024 07:16:35 -1000 Subject: [PATCH] dev: amountStripPrices -> amountStripCost --- bin/hledger-move.hs | 4 ++-- hledger-lib/Hledger/Data/Amount.hs | 10 +++++----- hledger-lib/Hledger/Data/Balancing.hs | 4 ++-- hledger-lib/Hledger/Data/Posting.hs | 2 +- hledger/Hledger/Cli/Commands/Print.hs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bin/hledger-move.hs b/bin/hledger-move.hs index 08b9c2c90..606b421a4 100755 --- a/bin/hledger-move.hs +++ b/bin/hledger-move.hs @@ -156,7 +156,7 @@ main = do force = boolopt "force" rawopts -- parse the AMT arg as a cost-less Amount (any provided cost is ignored) - eamt = styleAmount (journalCommodityStyles j) . amountStripPrices <$> parseamount amtarg + eamt = styleAmount (journalCommodityStyles j) . amountStripCost <$> parseamount amtarg amt = case eamt of Left err -> error' $ "could not parse " ++ show amtarg ++ " as a hledger amount\n" ++ customErrorBundlePretty err ++ "\n" ++shortusage @@ -220,7 +220,7 @@ main = do ++ showMixedAmountOneLine balincomm ++ ")" -- subtract this from the amount remaining to move (ignoring cost) stilltomovenext = dbgamt "remaining amt to move" $ - stilltomove - amountStripPrices balincommsinglecost + stilltomove - amountStripCost balincommsinglecost -- since balance assertion amounts are required to be exact, the -- amounts in opening/closing transactions should be too (#941, #1137) diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index bacee77ce..cbcf2fe07 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -103,7 +103,7 @@ module Hledger.Data.Amount ( withInternalPrecision, setAmountDecimalPoint, withDecimalPoint, - amountStripPrices, + amountStripCost, -- * MixedAmount nullmixedamt, @@ -335,6 +335,10 @@ amountCost a@Amount{aquantity=q, aprice=mp} = Just (UnitPrice p@Amount{aquantity=pq}) -> p{aquantity=pq * q} Just (TotalPrice p@Amount{aquantity=pq}) -> p{aquantity=pq} +-- | Strip all prices from an Amount +amountStripCost :: Amount -> Amount +amountStripCost a = a{aprice=Nothing} + -- | Apply a function to an amount's quantity (and its total price, if it has one). transformAmount :: (Quantity -> Quantity) -> Amount -> Amount transformAmount f a@Amount{aquantity=q,aprice=p} = a{aquantity=f q, aprice=f' <$> p} @@ -613,10 +617,6 @@ withDecimalPoint = flip setAmountDecimalPoint -- Amount rendering --- | Strip all prices from an Amount -amountStripPrices :: Amount -> Amount -amountStripPrices a = a{aprice=Nothing} - showAmountCostB :: Amount -> WideBuilder showAmountCostB amt = case aprice amt of Nothing -> mempty diff --git a/hledger-lib/Hledger/Data/Balancing.hs b/hledger-lib/Hledger/Data/Balancing.hs index 62ddc2c81..db3a6b829 100644 --- a/hledger-lib/Hledger/Data/Balancing.hs +++ b/hledger-lib/Hledger/Data/Balancing.hs @@ -647,8 +647,8 @@ checkBalanceAssertionOneCommodityB p@Posting{paccount=assertedacct} assertedcomm else return actualbal let assertedcomm = acommodity assertedcommbal - assertedcommbalcostless = amountStripPrices assertedcommbal - actualcommbalcostless = amountStripPrices . headDef nullamt . amountsRaw . filterMixedAmountByCommodity assertedcomm $ actualbal' + assertedcommbalcostless = amountStripCost assertedcommbal + actualcommbalcostless = amountStripCost . headDef nullamt . amountsRaw . filterMixedAmountByCommodity assertedcomm $ actualbal' -- test the assertion. Costs are ignored currently. pass = diff --git a/hledger-lib/Hledger/Data/Posting.hs b/hledger-lib/Hledger/Data/Posting.hs index 51df12c00..4915801c7 100644 --- a/hledger-lib/Hledger/Data/Posting.hs +++ b/hledger-lib/Hledger/Data/Posting.hs @@ -559,7 +559,7 @@ postingAddInferredEquityPostings verbosetags equityAcct p conversionPostings amt = case aprice amt of Nothing -> [] Just _ -> [ cp{ paccount = accountPrefix <> amtCommodity - , pamount = mixedAmount . negate $ amountStripPrices amt + , pamount = mixedAmount . negate $ amountStripCost amt } , cp{ paccount = accountPrefix <> costCommodity , pamount = mixedAmount cost diff --git a/hledger/Hledger/Cli/Commands/Print.hs b/hledger/Hledger/Cli/Commands/Print.hs index f94f6ddf6..69bece8f8 100644 --- a/hledger/Hledger/Cli/Commands/Print.hs +++ b/hledger/Hledger/Cli/Commands/Print.hs @@ -210,7 +210,7 @@ postingToCSV p = map (\(a@(Amount {aquantity=q,acommodity=c})) -> -- commodity goes into separate column, so we suppress it, along with digit group -- separators and prices - let a_ = amountStripPrices a{acommodity=""} in + let a_ = amountStripCost a{acommodity=""} in let showamt = wbToText . showAmountB csvDisplay in let amt = showamt a_ in let credit = if q < 0 then showamt $ negate a_ else "" in