fix: accept entries with unmatched equity conversion postings (#2045)
Since 1.29, we unconditionally run part of the --infer-cost logic to identify redundant costs/equity postings. This was too strict, raising an error whenever it could not find postings matching the equity postings. Now we do this (and also the explicit --infer-costs operation) as a best effort, leaving transactions unchanged if we can't detect matching postings. This is consistent with --infer-equity, --infer-market-prices, -B and -V.
This commit is contained in:
parent
122e7dae94
commit
3357c27390
@ -320,8 +320,11 @@ transactionInferCostsFromEquity dryrun acctTypes t = first (annotateErrorWithTra
|
|||||||
, Just newotherps <- deleteIdx np otherps
|
, Just newotherps <- deleteIdx np otherps
|
||||||
-> Right (transformPostingF np costp, (costps, if dryrun' then otherps else newotherps))
|
-> Right (transformPostingF np costp, (costps, if dryrun' then otherps else newotherps))
|
||||||
|
|
||||||
-- Otherwise it's too ambiguous to make a guess, so return an error.
|
-- Otherwise, do nothing, leaving the transaction unchanged.
|
||||||
| otherwise -> Left "There is not a unique posting which matches the conversion posting pair:"
|
-- We don't want to be over-zealous reporting problems here
|
||||||
|
-- since this is always called at least in dry run mode by
|
||||||
|
-- journalFinalise > journalMarkRedundantCosts. (#2045)
|
||||||
|
| otherwise -> Right (id, (costps, otherps))
|
||||||
|
|
||||||
-- If a posting with cost matches both the conversion amounts, return it along
|
-- If a posting with cost matches both the conversion amounts, return it along
|
||||||
-- with the matching amount which must be present in another non-conversion posting.
|
-- with the matching amount which must be present in another non-conversion posting.
|
||||||
|
|||||||
@ -507,51 +507,74 @@ $ hledger -f- print --infer-costs
|
|||||||
|
|
||||||
>=0
|
>=0
|
||||||
|
|
||||||
# 39. If a conversion pair matches several postings it should throw an error
|
# We now tend to just skip cost inference if it doesn't succeed. (#2045)
|
||||||
|
|
||||||
|
# # 39. If a conversion pair matches several postings it should throw an error
|
||||||
|
# <
|
||||||
|
# 2011/01/01
|
||||||
|
# expenses:foreign currency €100 @@ $135
|
||||||
|
# expenses:foreign trades €100 @@ $135
|
||||||
|
# equity:conversion €-100
|
||||||
|
# equity:conversion $135
|
||||||
|
# assets €-100
|
||||||
|
# assets $-135
|
||||||
|
|
||||||
|
# $ hledger -f- print --infer-costs
|
||||||
|
# >2 /There is not a unique posting which matches the conversion posting pair/
|
||||||
|
# >=1
|
||||||
|
|
||||||
|
# # 40. If a conversion pair does not match it should throw an error
|
||||||
|
# <
|
||||||
|
# 2011/01/01
|
||||||
|
# expenses:foreign currency €120
|
||||||
|
# equity:conversion €-100
|
||||||
|
# equity:conversion $135
|
||||||
|
# assets:extra $20
|
||||||
|
# assets €-20
|
||||||
|
# assets $-155
|
||||||
|
|
||||||
|
# $ hledger -f- print --infer-costs
|
||||||
|
# >2 /There is not a unique posting which matches the conversion posting pair/
|
||||||
|
# >=1
|
||||||
|
|
||||||
|
# # 41. Multiple conversion pairs which match a single posting should cause an
|
||||||
|
# # error, and should not match both ‘sides’ of the conversion
|
||||||
|
# <
|
||||||
|
# 2011/01/01
|
||||||
|
# expenses:foreign currency €100
|
||||||
|
# equity:conversion €-100
|
||||||
|
# equity:conversion $135
|
||||||
|
# equity:conversion €-100
|
||||||
|
# equity:conversion $135
|
||||||
|
# assets $-270
|
||||||
|
# assets €100
|
||||||
|
|
||||||
|
# $ hledger -f- print --infer-costs
|
||||||
|
# >2 /There is not a unique posting which matches the conversion posting pair/
|
||||||
|
# >=1
|
||||||
|
|
||||||
|
# 39. A multicommodity transaction with conversion postings that we can't
|
||||||
|
# automatically match up with the corresponding other postings should be ignored,
|
||||||
|
# not an error. (#2045)
|
||||||
<
|
<
|
||||||
2011/01/01
|
2023-01-01
|
||||||
expenses:foreign currency €100 @@ $135
|
Expenses:Gift HKD 118.00
|
||||||
expenses:foreign trades €100 @@ $135
|
Expenses:Personal HKD 118.00
|
||||||
equity:conversion €-100
|
Equity:Trading:Currency:INR-HKD:HKD HKD -236.00
|
||||||
equity:conversion $135
|
Equity:Trading:Currency:INR-HKD:INR ₹2,150.77
|
||||||
assets €-100
|
Liabilities:Credit-Card ₹-2,150.77
|
||||||
assets $-135
|
|
||||||
|
|
||||||
$ hledger -f- print --infer-costs
|
$ hledger -f- print
|
||||||
>2 /There is not a unique posting which matches the conversion posting pair/
|
2023-01-01
|
||||||
>=1
|
Expenses:Gift HKD 118.00
|
||||||
|
Expenses:Personal HKD 118.00
|
||||||
|
Equity:Trading:Currency:INR-HKD:HKD HKD -236.00
|
||||||
|
Equity:Trading:Currency:INR-HKD:INR ₹2,150.77
|
||||||
|
Liabilities:Credit-Card ₹-2,150.77
|
||||||
|
|
||||||
# 42. If a conversion pair does not match it should throw an error
|
>=
|
||||||
<
|
|
||||||
2011/01/01
|
|
||||||
expenses:foreign currency €120
|
|
||||||
equity:conversion €-100
|
|
||||||
equity:conversion $135
|
|
||||||
assets:extra $20
|
|
||||||
assets €-20
|
|
||||||
assets $-155
|
|
||||||
|
|
||||||
$ hledger -f- print --infer-costs
|
# 40. We can combine ‘other’ amounts into one posting, if they still match up.
|
||||||
>2 /There is not a unique posting which matches the conversion posting pair/
|
|
||||||
>=1
|
|
||||||
|
|
||||||
# 43. Multiple conversion pairs which match a single posting should cause an
|
|
||||||
# error, and should not match both ‘sides’ of the conversion
|
|
||||||
<
|
|
||||||
2011/01/01
|
|
||||||
expenses:foreign currency €100
|
|
||||||
equity:conversion €-100
|
|
||||||
equity:conversion $135
|
|
||||||
equity:conversion €-100
|
|
||||||
equity:conversion $135
|
|
||||||
assets $-270
|
|
||||||
assets €100
|
|
||||||
|
|
||||||
$ hledger -f- print --infer-costs
|
|
||||||
>2 /There is not a unique posting which matches the conversion posting pair/
|
|
||||||
>=1
|
|
||||||
|
|
||||||
# 44. We can combine ‘other’ amounts into one posting, if they still match up.
|
|
||||||
<
|
<
|
||||||
2011-01-01
|
2011-01-01
|
||||||
expenses:foreign currency €100 @ $1.35
|
expenses:foreign currency €100 @ $1.35
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user