From 71a7879213c28b71ed967ed0dd6094109f2f4897 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 14 Oct 2024 14:49:18 -1000 Subject: [PATCH] fix:check tags: _price-matched -> _cost-matched, and whitelisted [#2247] --- hledger-lib/Hledger/Data/Balancing.hs | 2 +- hledger-lib/Hledger/Data/JournalChecks.hs | 3 ++- hledger-lib/Hledger/Data/Posting.hs | 4 ++-- hledger-lib/Hledger/Data/Transaction.hs | 6 +++--- hledger/hledger.m4.md | 8 ++++++-- hledger/test/check-tags.test | 2 ++ 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/hledger-lib/Hledger/Data/Balancing.hs b/hledger-lib/Hledger/Data/Balancing.hs index 970466085..ffc95e155 100644 --- a/hledger-lib/Hledger/Data/Balancing.hs +++ b/hledger-lib/Hledger/Data/Balancing.hs @@ -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 diff --git a/hledger-lib/Hledger/Data/JournalChecks.hs b/hledger-lib/Hledger/Data/JournalChecks.hs index 43fe2ac19..adba53f0d 100644 --- a/hledger-lib/Hledger/Data/JournalChecks.hs +++ b/hledger-lib/Hledger/Data/JournalChecks.hs @@ -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. diff --git a/hledger-lib/Hledger/Data/Posting.hs b/hledger-lib/Hledger/Data/Posting.hs index 382acfe0d..b9230b88c 100644 --- a/hledger-lib/Hledger/Data/Posting.hs +++ b/hledger-lib/Hledger/Data/Posting.hs @@ -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 diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index 739fd2a49..8246afefb 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -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 diff --git a/hledger/hledger.m4.md b/hledger/hledger.m4.md index 50544f79d..1a8a8ce4c 100644 --- a/hledger/hledger.m4.md +++ b/hledger/hledger.m4.md @@ -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 diff --git a/hledger/test/check-tags.test b/hledger/test/check-tags.test index 766595eb9..240f4389f 100644 --- a/hledger/test/check-tags.test +++ b/hledger/test/check-tags.test @@ -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