@@ -65,13 +65,15 @@ data BalancingOpts = BalancingOpts
6565 , infer_balancing_costs_ :: Bool -- ^ Are we permitted to infer missing costs to balance transactions ?
6666 -- Distinct from InputOpts{infer_costs_}.
6767 , commodity_styles_ :: Maybe (M. Map CommoditySymbol AmountStyle ) -- ^ commodity display styles
68+ , txn_balancing_ :: TransactionBalancingPrecision
6869 } deriving (Eq , Ord , Show )
6970
7071defbalancingopts :: BalancingOpts
7172defbalancingopts = BalancingOpts
7273 { ignore_assertions_ = False
7374 , infer_balancing_costs_ = True
7475 , commodity_styles_ = Nothing
76+ , txn_balancing_ = TBPExact
7577 }
7678
7779-- | Check that this transaction would appear balanced to a human when displayed.
@@ -92,8 +94,7 @@ defbalancingopts = BalancingOpts
9294-- (using the given display styles if provided)
9395--
9496transactionCheckBalanced :: BalancingOpts -> Transaction -> [String ]
95- -- transactionCheckBalanced BalancingOpts{commodity_styles_=_mstyles} t = errs
96- transactionCheckBalanced _ t = errs
97+ transactionCheckBalanced BalancingOpts {commodity_styles_= _mglobalstyles, txn_balancing_} t = errs
9798 where
9899 -- get real and balanced virtual postings, to be checked separately
99100 (rps, bvps) = foldr partitionPosting ([] , [] ) $ tpostings t
@@ -110,9 +111,16 @@ transactionCheckBalanced _ t = errs
110111 | costPostingTagName `elem` map fst (ptags p) = mixedAmountStripCosts $ pamount p
111112 | otherwise = mixedAmountCost $ pamount p
112113
113- lookszero = mixedAmountLooksZero .
114- -- maybe id styleAmounts _mstyles -- when rounded with global/journal precisions
115- styleAmounts (transactionCommodityStylesWith HardRounding t) -- when rounded with transaction's precisions
114+ lookszero = mixedAmountLooksZero . roundforbalancecheck
115+ where
116+ roundforbalancecheck = case txn_balancing_ of
117+ TBPOld -> maybe id styleAmounts _mglobalstyles
118+ -- TBPCompat -> styleAmounts (transactionstyles `limitprecisionsto` commoditydirectivestyles)
119+ TBPExact -> styleAmounts transactionstyles
120+ where
121+ transactionstyles = transactionCommodityStylesWith HardRounding t
122+ -- limitprecisionsto = undefined
123+ -- commoditydirectivestyles = undefined
116124
117125 -- when there's multiple non-zeros, check they do not all have the same sign
118126 (rsignsok, bvsignsok) = (signsOk rps, signsOk bvps)
@@ -289,7 +297,7 @@ transactionInferBalancingAmount styles t@Transaction{tpostings=ps}
289297 & mixedAmountCost
290298 -- & dbg9With (lbl "balancing amount converted to cost".showMixedAmountOneLine)
291299 & styleAmounts (styles
292- -- Needed until we switch to locally-inferred balancing precisions:
300+ -- Needed until we switch to locally-inferred balancing precisions: XXX #2402
293301 -- these had hard rounding set to help with balanced-checking;
294302 -- set no rounding now to avoid excessive display precision in output
295303 & amountStylesSetRounding NoRounding
0 commit comments