lib: Hledger.Data.Amount: noPrice -> noCost

This commit is contained in:
Simon Michael 2023-12-07 14:39:52 -10:00
parent 862b7e5712
commit 0bc86c95e4
4 changed files with 14 additions and 14 deletions

View File

@ -80,7 +80,7 @@ module Hledger.Data.Amount (
-- ** rendering
AmountDisplayOpts(..),
noColour,
noPrice,
noCost,
oneLine,
csvDisplay,
showAmountB,
@ -174,7 +174,7 @@ import Data.List (find, foldl', intercalate, intersperse, mapAccumL, partition)
import Data.List.NonEmpty (NonEmpty(..), nonEmpty)
import qualified Data.Map.Strict as M
import qualified Data.Set as S
import Data.Maybe (fromMaybe, isNothing, isJust)
import Data.Maybe (fromMaybe, isNothing)
import Data.Semigroup (Semigroup(..))
import qualified Data.Text as T
import qualified Data.Text.Lazy.Builder as TB
@ -253,8 +253,8 @@ noColour = AmountDisplayOpts {
}
-- | Display Amount and MixedAmount with no prices.
noPrice :: AmountDisplayOpts
noPrice = def{displayCost=False}
noCost :: AmountDisplayOpts
noCost = def{displayCost=False}
-- | Display Amount and MixedAmount on one line with no prices.
oneLine :: AmountDisplayOpts
@ -682,9 +682,9 @@ cshowAmount = wbUnpack . showAmountB def{displayColour=True}
-- | Get the string representation of an amount, without any \@ price.
--
-- > showAmountWithoutPrice = wbUnpack . showAmountB noPrice
-- > showAmountWithoutPrice = wbUnpack . showAmountB noCost
showAmountWithoutPrice :: Amount -> String
showAmountWithoutPrice = wbUnpack . showAmountB noPrice
showAmountWithoutPrice = wbUnpack . showAmountB noCost
-- | Like showAmount, but show a zero amount's commodity if it has one.
--
@ -1057,9 +1057,9 @@ showMixedAmountWithZeroCommodity = wbUnpack . showMixedAmountB noColour{displayZ
-- | Get the string representation of a mixed amount, without showing any transaction prices.
-- With a True argument, adds ANSI codes to show negative amounts in red.
--
-- > showMixedAmountWithoutPrice c = wbUnpack . showMixedAmountB noPrice{displayColour=c}
-- > showMixedAmountWithoutPrice c = wbUnpack . showMixedAmountB noCost{displayColour=c}
showMixedAmountWithoutPrice :: Bool -> MixedAmount -> String
showMixedAmountWithoutPrice c = wbUnpack . showMixedAmountB noPrice{displayColour=c}
showMixedAmountWithoutPrice c = wbUnpack . showMixedAmountB noCost{displayColour=c}
-- | Get the one-line string representation of a mixed amount, but without
-- any \@ prices.

View File

@ -539,11 +539,11 @@ postingApplyValuation priceoracle styles periodlast today v p =
postingToCost :: ConversionOp -> Posting -> Maybe Posting
postingToCost NoConversionOp p = Just p
postingToCost ToCost p
-- If this is a conversion posting with a matched transaction price posting, ignore it
| "_conversion-matched" `elem` map fst (ptags p) && noCost = Nothing
| otherwise = Just $ postingTransformAmount mixedAmountCost p
-- If this is a conversion posting with a matched transaction price posting, ignore it
| "_conversion-matched" `elem` map fst (ptags p) && nocosts = Nothing
| otherwise = Just $ postingTransformAmount mixedAmountCost p
where
noCost = (not . any (isJust . aprice) . amountsRaw) $ pamount p
nocosts = (not . any (isJust . aprice) . amountsRaw) $ pamount p
-- | Generate inferred equity postings from a 'Posting' using transaction prices.
-- Make sure not to generate equity postings when there are already matched

View File

@ -339,7 +339,7 @@ budgetReportAsTable
LayoutWide width ->
( pure . showMixedAmountB oneLine{displayColour=color_, displayMaxWidth=width}
, \a -> pure . percentage a)
_ -> ( showMixedAmountLinesB noPrice{displayCommodityOrder=Just cs, displayMinWidth=Nothing, displayColour=color_}
_ -> ( showMixedAmountLinesB noCost{displayCommodityOrder=Just cs, displayMinWidth=Nothing, displayColour=color_}
, \a b -> fmap (percentage' a b) cs)
showrow :: [BudgetCell] -> [(WideBuilder, BudgetDisplayRow)]

View File

@ -524,7 +524,7 @@ renderComponent topaligned oneline opts (acctname, dep, total) (FormatField ljus
| topaligned = TopRight
| ljust = BottomLeft
| otherwise = BottomRight
dopts = noPrice{displayColour=color_ opts, displayOneLine=oneline, displayMinWidth=mmin, displayMaxWidth=mmax}
dopts = noCost{displayColour=color_ opts, displayOneLine=oneline, displayMinWidth=mmin, displayMaxWidth=mmax}
-- rendering multi-column balance reports