lib: Use uniform naming for stripping prices.

Creates a new function amountStripPrices, and renames removePrices to
postingStripPrices.
This commit is contained in:
Stephen Morgan 2021-03-22 18:12:33 +11:00 committed by Simon Michael
parent 42d7009fef
commit b7a2479186
4 changed files with 13 additions and 7 deletions

View File

@ -91,6 +91,7 @@ module Hledger.Data.Amount (
withInternalPrecision,
setAmountDecimalPoint,
withDecimalPoint,
amountStripPrices,
canonicaliseAmount,
-- * MixedAmount
nullmixedamt,
@ -376,6 +377,10 @@ setAmountDecimalPoint mc a@Amount{ astyle=s } = a{ astyle=s{asdecimalpoint=mc} }
withDecimalPoint :: Amount -> Maybe Char -> Amount
withDecimalPoint = flip setAmountDecimalPoint
-- | Strip all prices from an Amount
amountStripPrices :: Amount -> Amount
amountStripPrices a = a{aprice=Nothing}
showAmountPrice :: Amount -> WideBuilder
showAmountPrice amt = case aprice amt of
Nothing -> mempty
@ -914,8 +919,9 @@ mixedAmountSetPrecision p = mapMixedAmount (amountSetPrecision p)
mixedAmountSetFullPrecision :: MixedAmount -> MixedAmount
mixedAmountSetFullPrecision = mapMixedAmount amountSetFullPrecision
-- | Strip all prices from a MixedAmount.
mixedAmountStripPrices :: MixedAmount -> MixedAmount
mixedAmountStripPrices = mapMixedAmount (\a -> a{aprice=Nothing})
mixedAmountStripPrices = mapMixedAmount amountStripPrices
-- | Canonicalise a mixed amount's display styles using the provided commodity style map.
canonicaliseMixedAmount :: M.Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount

View File

@ -875,13 +875,13 @@ journalBalanceTransactions assrt j' =
balanceTransactionAndCheckAssertionsB :: Either Posting Transaction -> Balancing s ()
balanceTransactionAndCheckAssertionsB (Left p@Posting{}) =
-- update the account's running balance and check the balance assertion if any
void $ addAmountAndCheckAssertionB $ removePrices p
void . addAmountAndCheckAssertionB $ postingStripPrices p
balanceTransactionAndCheckAssertionsB (Right t@Transaction{tpostings=ps}) = do
-- make sure we can handle the balance assignments
mapM_ checkIllegalBalanceAssignmentB ps
-- for each posting, infer its amount from the balance assignment if applicable,
-- update the account's running balance and check the balance assertion if any
ps' <- forM ps $ \p -> pure (removePrices p) >>= addOrAssignAmountAndCheckAssertionB
ps' <- mapM (addOrAssignAmountAndCheckAssertionB . postingStripPrices) ps
-- infer any remaining missing amounts, and make sure the transaction is now fully balanced
styles <- R.reader bsStyles
case balanceTransactionHelper styles t{tpostings=ps'} of

View File

@ -37,7 +37,7 @@ module Hledger.Data.Posting (
postingAllTags,
transactionAllTags,
relatedPostings,
removePrices,
postingStripPrices,
postingApplyAliases,
-- * date operations
postingDate,
@ -201,8 +201,8 @@ sumPostings :: [Posting] -> MixedAmount
sumPostings = foldl' (\amt p -> maPlus amt $ pamount p) nullmixedamt
-- | Remove all prices of a posting
removePrices :: Posting -> Posting
removePrices = postingTransformAmount (mapMixedAmount $ \a -> a{aprice=Nothing})
postingStripPrices :: Posting -> Posting
postingStripPrices = postingTransformAmount mixedAmountStripPrices
-- | Get a posting's (primary) date - it's own primary date if specified,
-- otherwise the parent transaction's primary date, or the null date if

View File

@ -92,7 +92,7 @@ postingsReport rspec@ReportSpec{rsOpts=ropts@ReportOpts{..}} j = items
reportPeriodOrJournalLastDay rspec j
-- Posting report does not use prices after valuation, so remove them.
displaypsnoprices = map (\(p,md) -> (removePrices p, md)) displayps
displaypsnoprices = map (\(p,md) -> (postingStripPrices p, md)) displayps
-- Posting report items ready for display.
items =