dev: amountStripPrices -> amountStripCost

This commit is contained in:
Simon Michael 2024-01-23 07:16:35 -10:00
parent 0353840d90
commit e201775e93
5 changed files with 11 additions and 11 deletions

View File

@ -156,7 +156,7 @@ main = do
force = boolopt "force" rawopts force = boolopt "force" rawopts
-- parse the AMT arg as a cost-less Amount (any provided cost is ignored) -- 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 amt = case eamt of
Left err -> Left err ->
error' $ "could not parse " ++ show amtarg ++ " as a hledger amount\n" ++ customErrorBundlePretty err ++ "\n" ++shortusage error' $ "could not parse " ++ show amtarg ++ " as a hledger amount\n" ++ customErrorBundlePretty err ++ "\n" ++shortusage
@ -220,7 +220,7 @@ main = do
++ showMixedAmountOneLine balincomm ++ ")" ++ showMixedAmountOneLine balincomm ++ ")"
-- subtract this from the amount remaining to move (ignoring cost) -- subtract this from the amount remaining to move (ignoring cost)
stilltomovenext = dbgamt "remaining amt to move" $ stilltomovenext = dbgamt "remaining amt to move" $
stilltomove - amountStripPrices balincommsinglecost stilltomove - amountStripCost balincommsinglecost
-- since balance assertion amounts are required to be exact, the -- since balance assertion amounts are required to be exact, the
-- amounts in opening/closing transactions should be too (#941, #1137) -- amounts in opening/closing transactions should be too (#941, #1137)

View File

@ -103,7 +103,7 @@ module Hledger.Data.Amount (
withInternalPrecision, withInternalPrecision,
setAmountDecimalPoint, setAmountDecimalPoint,
withDecimalPoint, withDecimalPoint,
amountStripPrices, amountStripCost,
-- * MixedAmount -- * MixedAmount
nullmixedamt, nullmixedamt,
@ -335,6 +335,10 @@ amountCost a@Amount{aquantity=q, aprice=mp} =
Just (UnitPrice p@Amount{aquantity=pq}) -> p{aquantity=pq * q} Just (UnitPrice p@Amount{aquantity=pq}) -> p{aquantity=pq * q}
Just (TotalPrice p@Amount{aquantity=pq}) -> p{aquantity=pq} 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). -- | Apply a function to an amount's quantity (and its total price, if it has one).
transformAmount :: (Quantity -> Quantity) -> Amount -> Amount transformAmount :: (Quantity -> Quantity) -> Amount -> Amount
transformAmount f a@Amount{aquantity=q,aprice=p} = a{aquantity=f q, aprice=f' <$> p} transformAmount f a@Amount{aquantity=q,aprice=p} = a{aquantity=f q, aprice=f' <$> p}
@ -613,10 +617,6 @@ withDecimalPoint = flip setAmountDecimalPoint
-- Amount rendering -- Amount rendering
-- | Strip all prices from an Amount
amountStripPrices :: Amount -> Amount
amountStripPrices a = a{aprice=Nothing}
showAmountCostB :: Amount -> WideBuilder showAmountCostB :: Amount -> WideBuilder
showAmountCostB amt = case aprice amt of showAmountCostB amt = case aprice amt of
Nothing -> mempty Nothing -> mempty

View File

@ -647,8 +647,8 @@ checkBalanceAssertionOneCommodityB p@Posting{paccount=assertedacct} assertedcomm
else return actualbal else return actualbal
let let
assertedcomm = acommodity assertedcommbal assertedcomm = acommodity assertedcommbal
assertedcommbalcostless = amountStripPrices assertedcommbal assertedcommbalcostless = amountStripCost assertedcommbal
actualcommbalcostless = amountStripPrices . headDef nullamt . amountsRaw . filterMixedAmountByCommodity assertedcomm $ actualbal' actualcommbalcostless = amountStripCost . headDef nullamt . amountsRaw . filterMixedAmountByCommodity assertedcomm $ actualbal'
-- test the assertion. Costs are ignored currently. -- test the assertion. Costs are ignored currently.
pass = pass =

View File

@ -559,7 +559,7 @@ postingAddInferredEquityPostings verbosetags equityAcct p
conversionPostings amt = case aprice amt of conversionPostings amt = case aprice amt of
Nothing -> [] Nothing -> []
Just _ -> [ cp{ paccount = accountPrefix <> amtCommodity Just _ -> [ cp{ paccount = accountPrefix <> amtCommodity
, pamount = mixedAmount . negate $ amountStripPrices amt , pamount = mixedAmount . negate $ amountStripCost amt
} }
, cp{ paccount = accountPrefix <> costCommodity , cp{ paccount = accountPrefix <> costCommodity
, pamount = mixedAmount cost , pamount = mixedAmount cost

View File

@ -210,7 +210,7 @@ postingToCSV p =
map (\(a@(Amount {aquantity=q,acommodity=c})) -> map (\(a@(Amount {aquantity=q,acommodity=c})) ->
-- commodity goes into separate column, so we suppress it, along with digit group -- commodity goes into separate column, so we suppress it, along with digit group
-- separators and prices -- separators and prices
let a_ = amountStripPrices a{acommodity=""} in let a_ = amountStripCost a{acommodity=""} in
let showamt = wbToText . showAmountB csvDisplay in let showamt = wbToText . showAmountB csvDisplay in
let amt = showamt a_ in let amt = showamt a_ in
let credit = if q < 0 then showamt $ negate a_ else "" in let credit = if q < 0 then showamt $ negate a_ else "" in