journal: default commodity (D) limits display precision too (#1187)
D directives are now fully equivalent to commodity directives for setting a commodity's display style. (Previously it was equivalent to a posting amount, so it couldn't limit the number of decimal places.) When both kinds of directive exist, commodity directives take precedence. When there are multiple D directives in the journal, only the last one affects display style.
This commit is contained in:
parent
1741b607e2
commit
e4a0bdff8d
@ -921,15 +921,20 @@ journalApplyCommodityStyles j@Journal{jtxns=ts, jpricedirectives=pds} =
|
|||||||
fixbalanceassertion ba = ba{baamount=styleAmount styles $ baamount ba}
|
fixbalanceassertion ba = ba{baamount=styleAmount styles $ baamount ba}
|
||||||
fixpricedirective pd@PriceDirective{pdamount=a} = pd{pdamount=styleAmountExceptPrecision styles a}
|
fixpricedirective pd@PriceDirective{pdamount=a} = pd{pdamount=styleAmountExceptPrecision styles a}
|
||||||
|
|
||||||
-- | Get all the amount styles defined in this journal, either declared by
|
-- | Get the canonical amount styles for this journal, whether
|
||||||
-- a commodity directive or inferred from amounts, as a map from symbol to style.
|
-- declared by commodity directives, by the last default commodity (D)
|
||||||
-- Styles declared by commodity directives take precedence, and these also are
|
-- directive, or inferred from posting amounts, as a map from symbol
|
||||||
-- guaranteed to know their decimal point character.
|
-- to style. Styles declared by directives take precedence (and
|
||||||
|
-- commodity takes precedence over D). Styles from directives are
|
||||||
|
-- guaranteed to specify the decimal mark character.
|
||||||
journalCommodityStyles :: Journal -> M.Map CommoditySymbol AmountStyle
|
journalCommodityStyles :: Journal -> M.Map CommoditySymbol AmountStyle
|
||||||
journalCommodityStyles j = declaredstyles <> inferredstyles
|
journalCommodityStyles j =
|
||||||
|
-- XXX could be some redundancy here, cf journalStyleInfluencingAmounts
|
||||||
|
commoditystyles <> defaultcommoditystyle <> inferredstyles
|
||||||
where
|
where
|
||||||
declaredstyles = M.mapMaybe cformat $ jcommodities j
|
commoditystyles = M.mapMaybe cformat $ jcommodities j
|
||||||
inferredstyles = jinferredcommodities j
|
defaultcommoditystyle = M.fromList $ catMaybes [jparsedefaultcommodity j]
|
||||||
|
inferredstyles = jinferredcommodities j
|
||||||
|
|
||||||
-- | Collect and save inferred amount styles for each commodity based on
|
-- | Collect and save inferred amount styles for each commodity based on
|
||||||
-- the posting amounts in that commodity (excluding price amounts), ie:
|
-- the posting amounts in that commodity (excluding price amounts), ie:
|
||||||
|
|||||||
@ -56,19 +56,16 @@ $ hledger -f- print
|
|||||||
|
|
||||||
>=0
|
>=0
|
||||||
|
|
||||||
# 5. commodity and display style applied to the second posting amount..
|
# 5. A D directive affects all aspects of display style,
|
||||||
# which ends up setting the digit group style, since it's the first amount
|
# including limiting the display precision, like a commodity directive (#1187).
|
||||||
# with digit groups. The great precision is used.
|
|
||||||
<
|
<
|
||||||
D $1,000.0
|
D 1,000.0 A
|
||||||
2010/1/1
|
1/1
|
||||||
(a) $1000000.00
|
(a) 1000.123
|
||||||
(b) 1000000
|
|
||||||
|
|
||||||
$ hledger -f- print
|
$ hledger -f- print
|
||||||
2010-01-01
|
2020-01-01
|
||||||
(a) $1,000,000.00
|
(a) 1,000.1 A
|
||||||
(b) $1,000,000.00
|
|
||||||
|
|
||||||
>=0
|
>=0
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user