dev: amounts: cleanups

This commit is contained in:
Simon Michael 2023-08-28 07:25:37 +01:00
parent d3cc31780a
commit 9b15d34f9c
2 changed files with 9 additions and 6 deletions

View File

@ -197,6 +197,7 @@ quoteCommoditySymbolIfNeeded s
-- | Options for the display of Amount and MixedAmount.
-- (See also Types.AmountStyle)
data AmountDisplayOpts = AmountDisplayOpts
{ displayPrice :: Bool -- ^ Whether to display the Price of an Amount.
, displayZeroCommodity :: Bool -- ^ If the Amount rounds to 0, whether to display its commodity string.
@ -420,7 +421,7 @@ showAmountPriceDebug (Just (TotalPrice pa)) = " @@ " ++ showAmountDebug pa
-- | Given a map of standard commodity display styles, apply the
-- appropriate one to this amount. If there's no standard style for
-- this amount's commodity, return the amount unchanged.
-- Also apply the style to the price (except for precision)
-- Also apply the style, except for precision, to the cost.
styleAmount :: M.Map CommoditySymbol AmountStyle -> Amount -> Amount
styleAmount styles a = styledAmount{aprice = stylePrice styles (aprice styledAmount)}
where
@ -806,8 +807,8 @@ mixedAmountCost (Mixed ma) =
-- where a' = mixedAmountStripPrices a
-- b' = mixedAmountStripPrices b
-- | Given a map of standard commodity display styles, apply the
-- appropriate one to each individual amount.
-- | Given a map of standard commodity display styles, find and apply
-- the appropriate style to each individual amount.
styleMixedAmount :: M.Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount
styleMixedAmount styles = mapMixedAmountUnsafe (styleAmount styles)

View File

@ -250,6 +250,7 @@ data AmountPrice = UnitPrice !Amount | TotalPrice !Amount
deriving (Eq,Ord,Generic,Show)
-- | Display style for an amount.
-- (See also Amount.AmountDisplayOpts)
data AmountStyle = AmountStyle {
ascommodityside :: !Side, -- ^ does the symbol appear on the left or the right ?
ascommodityspaced :: !Bool, -- ^ space between symbol and quantity ?
@ -270,9 +271,10 @@ instance Show AmountStyle where
-- | The "display precision" for a hledger amount, by which we mean
-- the number of decimal digits to display to the right of the decimal mark.
-- This can be from 0 to 255 digits (the maximum supported by the Decimal library),
-- or NaturalPrecision meaning "show all significant decimal digits".
data AmountPrecision = Precision !Word8 | NaturalPrecision deriving (Eq,Ord,Read,Show,Generic)
data AmountPrecision =
Precision !Word8 -- ^ show this many decimal digits (0..255)
| NaturalPrecision -- ^ show all significant decimal digits stored internally
deriving (Eq,Ord,Read,Show,Generic)
-- | A style for displaying digit groups in the integer part of a
-- floating point number. It consists of the character used to