imp: journal: ignore redundant costs; --infer-costs more robustly
You can now write both @/@@ costs and corresponding equity conversion postings in a transaction at any time, not just when using --infer-costs or --infer-equity. hledger will recognise the redundancy and ignore it. One thing has become more strict: hledger now requires conversion postings to occur in adjacent pairs; an odd number of them is not allowed. (Conversion postings are postings to accounts of type `V`/`Conversion`, or named `equity:conversion`, `equity:trade`, `equity:trading`, or subaccounts of these.) And, --infer-costs now works in transactions with an implicit amount (inferring costs from equity now happens after transaction balancing, not before).
This commit is contained in:
parent
7432769d3c
commit
76f8eaf91a
@ -324,10 +324,10 @@ journalFinalise iopts@InputOpts{..} f txt pj = do
|
||||
>>= (if auto_ && not (null $ jtxnmodifiers pj)
|
||||
then journalAddAutoPostings _ioDay balancingopts_ -- Add auto postings if enabled, and account tags if needed
|
||||
else pure)
|
||||
>>= (if infer_costs_ then journalInferCostsFromEquity else pure) -- Maybe infer costs from equity postings where possible
|
||||
-- XXX ^ You might think this should happen after journalBalanceTransactions, since filling in a missing amount can help
|
||||
-- infer costs from equity. But currently ignoring excess inferred costs depends somehow on inferring them before balancing.
|
||||
-- >>= Right . dbg0With (concatMap (T.unpack.showTransaction).jtxns) -- debug
|
||||
>>= journalMarkRedundantCosts -- Mark redundant costs, to help journalBalanceTransactions ignore them
|
||||
>>= journalBalanceTransactions balancingopts_ -- Balance all transactions and maybe check balance assertions.
|
||||
>>= (if infer_costs_ then journalInferCostsFromEquity else pure) -- Maybe infer costs from equity postings where possible
|
||||
<&> (if infer_equity_ then journalAddInferredEquityPostings else id) -- Maybe infer equity postings from costs where possible
|
||||
<&> journalInferMarketPricesFromTransactions -- infer market prices from commodity-exchanging transactions
|
||||
<&> traceOrLogAt 6 ("journalFinalise: " <> takeFileName f) -- debug logging
|
||||
|
||||
@ -129,7 +129,9 @@ $ hledger -f- reg --auto type:x
|
||||
2022-02-02 Test
|
||||
(assets:cash) 1
|
||||
(equity:conversion) 2
|
||||
(equity:conversion) -2
|
||||
|
||||
$ hledger -f- reg type:ae
|
||||
2022-02-02 Test (assets:cash) 1 1
|
||||
(equity:conversion) 2 3
|
||||
(equity:conversion) -2 1
|
||||
|
||||
Loading…
Reference in New Issue
Block a user