fix:check tags: _price-matched -> _cost-matched, and whitelisted [#2247]

This commit is contained in:
Simon Michael 2024-10-14 14:49:18 -10:00
parent b8497c830e
commit 71a7879213
6 changed files with 16 additions and 9 deletions

View File

@ -104,7 +104,7 @@ transactionCheckBalanced BalancingOpts{commodity_styles_} t = errs
-- convert this posting's amount to cost,
-- without getting confused by redundant costs/equity postings
postingBalancingAmount p
| "_price-matched" `elem` map fst (ptags p) = mixedAmountStripCosts $ pamount p
| "_cost-matched" `elem` map fst (ptags p) = mixedAmountStripCosts $ pamount p
| otherwise = mixedAmountCost $ pamount p
-- transaction balancedness is checked at each commodity's display precision

View File

@ -232,7 +232,8 @@ builtinTags = [
,"_generated-transaction" -- always exists on generated periodic txns
,"_generated-posting" -- always exists on generated auto postings
,"_modified" -- always exists on txns which have had auto postings added
,"_conversion-matched" -- exists on postings which have been matched with a nearby @/@@ cost notation
,"_conversion-matched" -- marks postings with a cost which have been matched with a nearby pair of equity conversion postings
,"_cost-matched" -- marks equity conversion postings which have been matched with a nearby posting with a cost
]
-- | In each tranaction, check that any conversion postings occur in adjacent pairs.

View File

@ -466,13 +466,13 @@ postingToCost ToCost p
-- Make sure not to duplicate them when matching ones exist already.
postingAddInferredEquityPostings :: Bool -> Text -> Posting -> [Posting]
postingAddInferredEquityPostings verbosetags equityAcct p
| "_price-matched" `elem` map fst (ptags p) = [p]
| "_cost-matched" `elem` map fst (ptags p) = [p]
| otherwise = taggedPosting : concatMap conversionPostings costs
where
costs = filter (isJust . acost) . amountsRaw $ pamount p
taggedPosting
| null costs = p
| otherwise = p{ ptags = ("_price-matched","") : ptags p }
| otherwise = p{ ptags = ("_cost-matched","") : ptags p }
conversionPostings amt = case acost amt of
Nothing -> []
Just _ -> [ cp{ paccount = accountPrefix <> amtCommodity

View File

@ -299,7 +299,7 @@ transactionInferCostsFromEquity dryrun conversionaccts t = first (annotateErrorW
-- Approximately: given a pair of conversion postings to match,
-- and lists of the remaining unmatched costful and costless other postings,
-- 1. find (and consume) two other postings which match the two conversion postings
-- 2. add identifying tags to the four postings
-- 2. add identifying (hidden) tags to the four postings
-- 3. add an explicit cost, if missing, to one of the matched other postings
-- 4. or if there is a problem, raise an informative error or do nothing as appropriate.
-- Or, if the first argument is true:
@ -326,8 +326,8 @@ transactionInferCostsFromEquity dryrun conversionaccts t = first (annotateErrorW
-- A function that adds a cost and/or tag to a numbered posting if appropriate.
postingAddCostAndOrTag np costp (n,p) =
(n, if | n == np -> costp `postingAddTags` [("_price-matched","")]
| n == n1 || n == n2 -> p `postingAddTags` [("_conversion-matched","")]
(n, if | n == np -> costp `postingAddTags` [("_cost-matched","")] -- add this tag to the posting with a cost
| n == n1 || n == n2 -> p `postingAddTags` [("_conversion-matched","")] -- add this tag to the two equity conversion postings
| otherwise -> p)
-- Annotate any errors with the conversion posting pair

View File

@ -1805,6 +1805,7 @@ Tags you can set to influence hledger's behaviour:
date2 -- overrides a posting's secondary date
type -- declares an account's type
```
Tags hledger adds to indicate generated data:
```
t -- appears on postings generated by timedot letters
@ -1814,14 +1815,17 @@ Tags hledger adds to indicate generated data:
generated-transaction -- appears on generated periodic txns (with --verbose-tags)
generated-posting -- appears on generated auto postings (with --verbose-tags)
modified -- appears on txns which have had auto postings added (with --verbose-tags)
Not displayed, but queryable:
_generated-transaction -- exists on generated periodic txns (always)
_generated-posting -- exists on generated auto postings (always)
_modified -- exists on txns which have had auto postings added (always)
```
Tags hledger uses internally:
Other tags hledger uses internally:
```
_conversion-matched -- exists on postings which have been matched with a nearby @/@@ cost annotation
_cost-matched -- marks postings with a cost which have been matched with a nearby pair of equity conversion postings
_conversion-matched -- marks equity conversion postings which have been matched with a nearby posting with a cost
```
### Tag values

View File

@ -58,6 +58,7 @@ $ hledger -f - check tags
; _generated-posting:
; _modified:
; _conversion-matched:
; _cost-matched:
$ hledger -f - check tags
# ** 7. Declaring the built-in special tags is harmless.
@ -77,4 +78,5 @@ tag _generated-transaction ; always exists on generated periodic txns
tag _generated-posting ; always exists on generated auto postings
tag _modified ; always exists on txns which have had auto postings added
tag _conversion-matched ; exists on postings which have been matched with a nearby @/@@ cost notation
tag _cost-matched ; exists on postings which have been matched with a nearby @/@@ cost notation
$ hledger -f - check tags