lib: Use uniform naming for stripping prices.
Creates a new function amountStripPrices, and renames removePrices to postingStripPrices.
This commit is contained in:
parent
42d7009fef
commit
b7a2479186
@ -91,6 +91,7 @@ module Hledger.Data.Amount (
|
|||||||
withInternalPrecision,
|
withInternalPrecision,
|
||||||
setAmountDecimalPoint,
|
setAmountDecimalPoint,
|
||||||
withDecimalPoint,
|
withDecimalPoint,
|
||||||
|
amountStripPrices,
|
||||||
canonicaliseAmount,
|
canonicaliseAmount,
|
||||||
-- * MixedAmount
|
-- * MixedAmount
|
||||||
nullmixedamt,
|
nullmixedamt,
|
||||||
@ -376,6 +377,10 @@ setAmountDecimalPoint mc a@Amount{ astyle=s } = a{ astyle=s{asdecimalpoint=mc} }
|
|||||||
withDecimalPoint :: Amount -> Maybe Char -> Amount
|
withDecimalPoint :: Amount -> Maybe Char -> Amount
|
||||||
withDecimalPoint = flip setAmountDecimalPoint
|
withDecimalPoint = flip setAmountDecimalPoint
|
||||||
|
|
||||||
|
-- | Strip all prices from an Amount
|
||||||
|
amountStripPrices :: Amount -> Amount
|
||||||
|
amountStripPrices a = a{aprice=Nothing}
|
||||||
|
|
||||||
showAmountPrice :: Amount -> WideBuilder
|
showAmountPrice :: Amount -> WideBuilder
|
||||||
showAmountPrice amt = case aprice amt of
|
showAmountPrice amt = case aprice amt of
|
||||||
Nothing -> mempty
|
Nothing -> mempty
|
||||||
@ -914,8 +919,9 @@ mixedAmountSetPrecision p = mapMixedAmount (amountSetPrecision p)
|
|||||||
mixedAmountSetFullPrecision :: MixedAmount -> MixedAmount
|
mixedAmountSetFullPrecision :: MixedAmount -> MixedAmount
|
||||||
mixedAmountSetFullPrecision = mapMixedAmount amountSetFullPrecision
|
mixedAmountSetFullPrecision = mapMixedAmount amountSetFullPrecision
|
||||||
|
|
||||||
|
-- | Strip all prices from a MixedAmount.
|
||||||
mixedAmountStripPrices :: MixedAmount -> 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.
|
-- | Canonicalise a mixed amount's display styles using the provided commodity style map.
|
||||||
canonicaliseMixedAmount :: M.Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount
|
canonicaliseMixedAmount :: M.Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount
|
||||||
|
|||||||
@ -875,13 +875,13 @@ journalBalanceTransactions assrt j' =
|
|||||||
balanceTransactionAndCheckAssertionsB :: Either Posting Transaction -> Balancing s ()
|
balanceTransactionAndCheckAssertionsB :: Either Posting Transaction -> Balancing s ()
|
||||||
balanceTransactionAndCheckAssertionsB (Left p@Posting{}) =
|
balanceTransactionAndCheckAssertionsB (Left p@Posting{}) =
|
||||||
-- update the account's running balance and check the balance assertion if any
|
-- 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
|
balanceTransactionAndCheckAssertionsB (Right t@Transaction{tpostings=ps}) = do
|
||||||
-- make sure we can handle the balance assignments
|
-- make sure we can handle the balance assignments
|
||||||
mapM_ checkIllegalBalanceAssignmentB ps
|
mapM_ checkIllegalBalanceAssignmentB ps
|
||||||
-- for each posting, infer its amount from the balance assignment if applicable,
|
-- 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
|
-- 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
|
-- infer any remaining missing amounts, and make sure the transaction is now fully balanced
|
||||||
styles <- R.reader bsStyles
|
styles <- R.reader bsStyles
|
||||||
case balanceTransactionHelper styles t{tpostings=ps'} of
|
case balanceTransactionHelper styles t{tpostings=ps'} of
|
||||||
|
|||||||
@ -37,7 +37,7 @@ module Hledger.Data.Posting (
|
|||||||
postingAllTags,
|
postingAllTags,
|
||||||
transactionAllTags,
|
transactionAllTags,
|
||||||
relatedPostings,
|
relatedPostings,
|
||||||
removePrices,
|
postingStripPrices,
|
||||||
postingApplyAliases,
|
postingApplyAliases,
|
||||||
-- * date operations
|
-- * date operations
|
||||||
postingDate,
|
postingDate,
|
||||||
@ -201,8 +201,8 @@ sumPostings :: [Posting] -> MixedAmount
|
|||||||
sumPostings = foldl' (\amt p -> maPlus amt $ pamount p) nullmixedamt
|
sumPostings = foldl' (\amt p -> maPlus amt $ pamount p) nullmixedamt
|
||||||
|
|
||||||
-- | Remove all prices of a posting
|
-- | Remove all prices of a posting
|
||||||
removePrices :: Posting -> Posting
|
postingStripPrices :: Posting -> Posting
|
||||||
removePrices = postingTransformAmount (mapMixedAmount $ \a -> a{aprice=Nothing})
|
postingStripPrices = postingTransformAmount mixedAmountStripPrices
|
||||||
|
|
||||||
-- | Get a posting's (primary) date - it's own primary date if specified,
|
-- | 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
|
-- otherwise the parent transaction's primary date, or the null date if
|
||||||
|
|||||||
@ -92,7 +92,7 @@ postingsReport rspec@ReportSpec{rsOpts=ropts@ReportOpts{..}} j = items
|
|||||||
reportPeriodOrJournalLastDay rspec j
|
reportPeriodOrJournalLastDay rspec j
|
||||||
|
|
||||||
-- Posting report does not use prices after valuation, so remove them.
|
-- 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.
|
-- Posting report items ready for display.
|
||||||
items =
|
items =
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user