diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index 48eab34d1..9dfeee123 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -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 diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index b8867166d..53df742df 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -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 diff --git a/hledger-lib/Hledger/Data/Posting.hs b/hledger-lib/Hledger/Data/Posting.hs index c06bbbf16..b980b6744 100644 --- a/hledger-lib/Hledger/Data/Posting.hs +++ b/hledger-lib/Hledger/Data/Posting.hs @@ -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 diff --git a/hledger-lib/Hledger/Reports/PostingsReport.hs b/hledger-lib/Hledger/Reports/PostingsReport.hs index 052d5be1c..600d1bcac 100644 --- a/hledger-lib/Hledger/Reports/PostingsReport.hs +++ b/hledger-lib/Hledger/Reports/PostingsReport.hs @@ -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 =