From 28eb8be4fa86636dbd2e39974f3251089dbb11d1 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 19 Jan 2023 20:18:53 -1000 Subject: [PATCH] lib: BalancingOpts{infer_transaction_prices_ -> infer_balancing_costs_} --- hledger-lib/Hledger/Data/Balancing.hs | 19 ++++++++++--------- hledger-lib/Hledger/Read/Common.hs | 8 ++++---- hledger-lib/Hledger/Read/InputOptions.hs | 6 +++--- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/hledger-lib/Hledger/Data/Balancing.hs b/hledger-lib/Hledger/Data/Balancing.hs index 227ad8aa2..12c9084b0 100644 --- a/hledger-lib/Hledger/Data/Balancing.hs +++ b/hledger-lib/Hledger/Data/Balancing.hs @@ -56,16 +56,17 @@ import Hledger.Data.Errors data BalancingOpts = BalancingOpts - { ignore_assertions_ :: Bool -- ^ Ignore balance assertions - , infer_transaction_prices_ :: Bool -- ^ Infer prices in unbalanced multicommodity amounts - , commodity_styles_ :: Maybe (M.Map CommoditySymbol AmountStyle) -- ^ commodity display styles + { ignore_assertions_ :: Bool -- ^ should failing balance assertions be ignored ? + , infer_balancing_costs_ :: Bool -- ^ Are we permitted to infer missing costs to balance transactions ? + -- Distinct from InputOpts{infer_costs_}. + , commodity_styles_ :: Maybe (M.Map CommoditySymbol AmountStyle) -- ^ commodity display styles } deriving (Show) defbalancingopts :: BalancingOpts defbalancingopts = BalancingOpts - { ignore_assertions_ = False - , infer_transaction_prices_ = True - , commodity_styles_ = Nothing + { ignore_assertions_ = False + , infer_balancing_costs_ = True + , commodity_styles_ = Nothing } -- | Check that this transaction would appear balanced to a human when displayed. @@ -156,7 +157,7 @@ balanceTransactionHelper :: -> Either String (Transaction, [(AccountName, MixedAmount)]) balanceTransactionHelper bopts t = do (t', inferredamtsandaccts) <- transactionInferBalancingAmount (fromMaybe M.empty $ commodity_styles_ bopts) $ - if infer_transaction_prices_ bopts then transactionInferBalancingCosts t else t + if infer_balancing_costs_ bopts then transactionInferBalancingCosts t else t case transactionCheckBalanced bopts t' of [] -> Right (txnTieKnot t', inferredamtsandaccts) errs -> Left $ transactionBalanceError t' errs' @@ -164,7 +165,7 @@ balanceTransactionHelper bopts t = do ismulticommodity = (length $ transactionCommodities t') > 1 errs' = [ "Automatic commodity conversion is not enabled." - | ismulticommodity && not (infer_transaction_prices_ bopts) + | ismulticommodity && not (infer_balancing_costs_ bopts) ] ++ errs ++ if ismulticommodity @@ -245,7 +246,7 @@ transactionInferBalancingAmount styles t@Transaction{tpostings=ps} a' = styleMixedAmount styles . mixedAmountCost $ maNegate a -- | Infer costs for this transaction's posting amounts, if needed to make --- the postings balance, and if possible. This is done once for the real +-- the postings balance, and if permitted. This is done once for the real -- postings and again (separately) for the balanced virtual postings. When -- it's not possible, the transaction is left unchanged. -- diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 8685ff9ae..11e8afcfb 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -190,7 +190,7 @@ instance Show (Reader m) where show r = rFormat r ++ " reader" rawOptsToInputOpts :: Day -> RawOpts -> InputOpts rawOptsToInputOpts day rawopts = - let noinferprice = boolopt "strict" rawopts || stringopt "args" rawopts == "balancednoautoconversion" + let noinferbalancingcosts = boolopt "strict" rawopts || stringopt "args" rawopts == "balancednoautoconversion" -- Do we really need to do all this work just to get the requested end date? This is duplicating -- much of reportOptsToSpec. @@ -216,9 +216,9 @@ rawOptsToInputOpts day rawopts = ,infer_equity_ = boolopt "infer-equity" rawopts && conversionop_ ropts /= Just ToCost ,infer_costs_ = boolopt "infer-costs" rawopts ,balancingopts_ = defbalancingopts{ - ignore_assertions_ = boolopt "ignore-assertions" rawopts - , infer_transaction_prices_ = not noinferprice - , commodity_styles_ = Just styles + ignore_assertions_ = boolopt "ignore-assertions" rawopts + , infer_balancing_costs_ = not noinferbalancingcosts + , commodity_styles_ = Just styles } ,strict_ = boolopt "strict" rawopts ,_ioDay = day diff --git a/hledger-lib/Hledger/Read/InputOptions.hs b/hledger-lib/Hledger/Read/InputOptions.hs index 9365951c7..08cfb4113 100644 --- a/hledger-lib/Hledger/Read/InputOptions.hs +++ b/hledger-lib/Hledger/Read/InputOptions.hs @@ -35,9 +35,9 @@ data InputOpts = InputOpts { ,pivot_ :: String -- ^ use the given field's value as the account name ,forecast_ :: Maybe DateSpan -- ^ span in which to generate forecast transactions ,reportspan_ :: DateSpan -- ^ a dirty hack keeping the query dates in InputOpts. This rightfully lives in ReportSpec, but is duplicated here. - ,auto_ :: Bool -- ^ generate automatic postings when journal is parsed - ,infer_equity_ :: Bool -- ^ generate automatic equity postings from transaction prices - ,infer_costs_ :: Bool -- ^ infer transaction prices from equity conversion postings + ,auto_ :: Bool -- ^ generate automatic postings when journal is parsed ? + ,infer_equity_ :: Bool -- ^ infer equity conversion postings from costs ? + ,infer_costs_ :: Bool -- ^ infer costs from equity conversion postings ? distinct from BalancingOpts{infer_balancing_costs_} ,balancingopts_ :: BalancingOpts -- ^ options for balancing transactions ,strict_ :: Bool -- ^ do extra error checking (eg, all posted accounts are declared, no prices are inferred) ,_ioDay :: Day -- ^ today's date, for use with forecast transactions XXX this duplicates _rsDay, and should eventually be removed when it's not needed anymore.