diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 7fd9b8bec34..e1f46f8adf0 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -98,6 +98,7 @@ module Hledger.Read.Common ( emptyorcommentlinep, followingcommentp, transactioncommentp, + commenttagsp, postingcommentp, -- ** bracketed dates diff --git a/hledger-lib/Hledger/Read/RulesReader.hs b/hledger-lib/Hledger/Read/RulesReader.hs index 6dd890508e1..c0c5c703a5e 100644 --- a/hledger-lib/Hledger/Read/RulesReader.hs +++ b/hledger-lib/Hledger/Read/RulesReader.hs @@ -75,9 +75,10 @@ import Text.Printf (printf) import Hledger.Data import Hledger.Utils -import Hledger.Read.Common (aliasesFromOpts, Reader(..), InputOpts(..), amountp, statusp, journalFinalise, accountnamep ) +import Hledger.Read.Common (aliasesFromOpts, Reader(..), InputOpts(..), amountp, statusp, journalFinalise, accountnamep, commenttagsp ) import Hledger.Read.CsvUtils import System.Directory (doesFileExist, getHomeDirectory) +import Data.Either (fromRight) --- ** doctest setup -- $setup @@ -1067,6 +1068,7 @@ transactionFromCsvRecord timesarezoned mtzin tzout sourcepos rules record = t code = maybe "" singleline' $ fieldval "code" description = maybe "" singleline' $ fieldval "description" comment = maybe "" unescapeNewlines $ fieldval "comment" + ttags = fromRight [] $ rtp commenttagsp comment precomment = maybe "" unescapeNewlines $ fieldval "precomment" singleline' = T.unwords . filter (not . T.null) . map T.strip . T.lines @@ -1079,6 +1081,7 @@ transactionFromCsvRecord timesarezoned mtzin tzout sourcepos rules record = t p1IsVirtual = (accountNamePostingType <$> fieldval "account1") == Just VirtualPosting ps = [p | n <- [1..maxpostings] ,let cmt = maybe "" unescapeNewlines $ fieldval ("comment"<> T.pack (show n)) + ,let ptags = fromRight [] $ rtp commenttagsp cmt ,let currency = fromMaybe "" (fieldval ("currency"<> T.pack (show n)) <|> fieldval "currency") ,let mamount = getAmount rules record currency p1IsVirtual n ,let mbalance = getBalance rules record currency n @@ -1091,6 +1094,7 @@ transactionFromCsvRecord timesarezoned mtzin tzout sourcepos rules record = t ,ptransaction = Just t ,pbalanceassertion = mkBalanceAssertion rules record <$> mbalance ,pcomment = cmt + ,ptags = ptags ,ptype = accountNamePostingType acct } ] @@ -1106,6 +1110,7 @@ transactionFromCsvRecord timesarezoned mtzin tzout sourcepos rules record = t ,tcode = code ,tdescription = description ,tcomment = comment + ,ttags = ttags ,tprecedingcomment = precomment ,tpostings = ps } diff --git a/hledger/test/csv.test b/hledger/test/csv.test index b4e42f7763f..5cea3de07e6 100644 --- a/hledger/test/csv.test +++ b/hledger/test/csv.test @@ -561,7 +561,7 @@ $ ./csvtest.sh >=0 -# ** 27. match a specific field +# ** 27. query by description < 2020-01-01, 1 2020-01-01, 2 @@ -1094,7 +1094,30 @@ $ ./csvtest.sh >2 /unexpected space/ >=1 -## . +# ** 56. match transaction by posting tag (#2114) +< +2020-01-01, 1 +RULES +fields date, desc +if %desc 1 + comment ttag:tval + comment1 ptag:pval + account1 a + +$ ./csvtest.sh tag:ptag +2020-01-01 ; ttag:tval + a ; ptag:pval + +>= + +# ** 57. match transaction by transaction tag (#2114) +$ ./csvtest.sh tag:ttag +2020-01-01 ; ttag:tval + a ; ptag:pval + +>= + +# ** . #< #$ ./csvtest.sh #>=0