lib: BalancingOpts{infer_transaction_prices_ -> infer_balancing_costs_}
This commit is contained in:
parent
c0950c0900
commit
28eb8be4fa
@ -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.
|
||||
--
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user