mirror of
https://github.com/simonmichael/hledger.git
synced 2024-10-06 19:07:27 +03:00
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
9d61e8193d
commit
bdac0da310
@ -320,8 +320,11 @@ transactionInferCostsFromEquity dryrun acctTypes t = first (annotateErrorWithTra
|
||||
, Just newotherps <- deleteIdx np otherps
|
||||
-> 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 -> Left "There is not a unique posting which matches the conversion posting pair:"
|
||||
-- Otherwise, do nothing, leaving the transaction unchanged.
|
||||
-- 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
|
||||
-- with the matching amount which must be present in another non-conversion posting.
|
||||
|
@ -507,51 +507,74 @@ $ hledger -f- print --infer-costs
|
||||
|
||||
>=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
|
||||
expenses:foreign currency €100 @@ $135
|
||||
expenses:foreign trades €100 @@ $135
|
||||
equity:conversion €-100
|
||||
equity:conversion $135
|
||||
assets €-100
|
||||
assets $-135
|
||||
2023-01-01
|
||||
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
|
||||
|
||||
$ hledger -f- print --infer-costs
|
||||
>2 /There is not a unique posting which matches the conversion posting pair/
|
||||
>=1
|
||||
$ hledger -f- print
|
||||
2023-01-01
|
||||
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
|
||||
>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.
|
||||
# 40. We can combine ‘other’ amounts into one posting, if they still match up.
|
||||
<
|
||||
2011-01-01
|
||||
expenses:foreign currency €100 @ $1.35
|
||||
|
Loading…
Reference in New Issue
Block a user