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
|
data BalancingOpts = BalancingOpts
|
||||||
{ ignore_assertions_ :: Bool -- ^ Ignore balance assertions
|
{ ignore_assertions_ :: Bool -- ^ should failing balance assertions be ignored ?
|
||||||
, infer_transaction_prices_ :: Bool -- ^ Infer prices in unbalanced multicommodity amounts
|
, infer_balancing_costs_ :: Bool -- ^ Are we permitted to infer missing costs to balance transactions ?
|
||||||
, commodity_styles_ :: Maybe (M.Map CommoditySymbol AmountStyle) -- ^ commodity display styles
|
-- Distinct from InputOpts{infer_costs_}.
|
||||||
|
, commodity_styles_ :: Maybe (M.Map CommoditySymbol AmountStyle) -- ^ commodity display styles
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
defbalancingopts :: BalancingOpts
|
defbalancingopts :: BalancingOpts
|
||||||
defbalancingopts = BalancingOpts
|
defbalancingopts = BalancingOpts
|
||||||
{ ignore_assertions_ = False
|
{ ignore_assertions_ = False
|
||||||
, infer_transaction_prices_ = True
|
, infer_balancing_costs_ = True
|
||||||
, commodity_styles_ = Nothing
|
, commodity_styles_ = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Check that this transaction would appear balanced to a human when displayed.
|
-- | Check that this transaction would appear balanced to a human when displayed.
|
||||||
@ -156,7 +157,7 @@ balanceTransactionHelper ::
|
|||||||
-> Either String (Transaction, [(AccountName, MixedAmount)])
|
-> Either String (Transaction, [(AccountName, MixedAmount)])
|
||||||
balanceTransactionHelper bopts t = do
|
balanceTransactionHelper bopts t = do
|
||||||
(t', inferredamtsandaccts) <- transactionInferBalancingAmount (fromMaybe M.empty $ commodity_styles_ bopts) $
|
(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
|
case transactionCheckBalanced bopts t' of
|
||||||
[] -> Right (txnTieKnot t', inferredamtsandaccts)
|
[] -> Right (txnTieKnot t', inferredamtsandaccts)
|
||||||
errs -> Left $ transactionBalanceError t' errs'
|
errs -> Left $ transactionBalanceError t' errs'
|
||||||
@ -164,7 +165,7 @@ balanceTransactionHelper bopts t = do
|
|||||||
ismulticommodity = (length $ transactionCommodities t') > 1
|
ismulticommodity = (length $ transactionCommodities t') > 1
|
||||||
errs' =
|
errs' =
|
||||||
[ "Automatic commodity conversion is not enabled."
|
[ "Automatic commodity conversion is not enabled."
|
||||||
| ismulticommodity && not (infer_transaction_prices_ bopts)
|
| ismulticommodity && not (infer_balancing_costs_ bopts)
|
||||||
] ++
|
] ++
|
||||||
errs ++
|
errs ++
|
||||||
if ismulticommodity
|
if ismulticommodity
|
||||||
@ -245,7 +246,7 @@ transactionInferBalancingAmount styles t@Transaction{tpostings=ps}
|
|||||||
a' = styleMixedAmount styles . mixedAmountCost $ maNegate a
|
a' = styleMixedAmount styles . mixedAmountCost $ maNegate a
|
||||||
|
|
||||||
-- | Infer costs for this transaction's posting amounts, if needed to make
|
-- | 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
|
-- postings and again (separately) for the balanced virtual postings. When
|
||||||
-- it's not possible, the transaction is left unchanged.
|
-- 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 -> InputOpts
|
||||||
rawOptsToInputOpts day rawopts =
|
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
|
-- Do we really need to do all this work just to get the requested end date? This is duplicating
|
||||||
-- much of reportOptsToSpec.
|
-- much of reportOptsToSpec.
|
||||||
@ -216,9 +216,9 @@ rawOptsToInputOpts day rawopts =
|
|||||||
,infer_equity_ = boolopt "infer-equity" rawopts && conversionop_ ropts /= Just ToCost
|
,infer_equity_ = boolopt "infer-equity" rawopts && conversionop_ ropts /= Just ToCost
|
||||||
,infer_costs_ = boolopt "infer-costs" rawopts
|
,infer_costs_ = boolopt "infer-costs" rawopts
|
||||||
,balancingopts_ = defbalancingopts{
|
,balancingopts_ = defbalancingopts{
|
||||||
ignore_assertions_ = boolopt "ignore-assertions" rawopts
|
ignore_assertions_ = boolopt "ignore-assertions" rawopts
|
||||||
, infer_transaction_prices_ = not noinferprice
|
, infer_balancing_costs_ = not noinferbalancingcosts
|
||||||
, commodity_styles_ = Just styles
|
, commodity_styles_ = Just styles
|
||||||
}
|
}
|
||||||
,strict_ = boolopt "strict" rawopts
|
,strict_ = boolopt "strict" rawopts
|
||||||
,_ioDay = day
|
,_ioDay = day
|
||||||
|
|||||||
@ -35,9 +35,9 @@ data InputOpts = InputOpts {
|
|||||||
,pivot_ :: String -- ^ use the given field's value as the account name
|
,pivot_ :: String -- ^ use the given field's value as the account name
|
||||||
,forecast_ :: Maybe DateSpan -- ^ span in which to generate forecast transactions
|
,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.
|
,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
|
,auto_ :: Bool -- ^ generate automatic postings when journal is parsed ?
|
||||||
,infer_equity_ :: Bool -- ^ generate automatic equity postings from transaction prices
|
,infer_equity_ :: Bool -- ^ infer equity conversion postings from costs ?
|
||||||
,infer_costs_ :: Bool -- ^ infer transaction prices from equity conversion postings
|
,infer_costs_ :: Bool -- ^ infer costs from equity conversion postings ? distinct from BalancingOpts{infer_balancing_costs_}
|
||||||
,balancingopts_ :: BalancingOpts -- ^ options for balancing transactions
|
,balancingopts_ :: BalancingOpts -- ^ options for balancing transactions
|
||||||
,strict_ :: Bool -- ^ do extra error checking (eg, all posted accounts are declared, no prices are inferred)
|
,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.
|
,_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