From 6e7575317a43c2945981dc4dfcf8b9630e5c87e0 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 5 Apr 2023 08:18:10 -1000 Subject: [PATCH] imp: "type:" queries now see through aliases/pivots, like acct: (fix #2018) When doing a type: match we now also check the original unaliased, unpivoted posting, as when doing an acct: match. This is effectively how things worked with the older account type detection in hledger <1.27. --- hledger-lib/Hledger/Query.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hledger-lib/Hledger/Query.hs b/hledger-lib/Hledger/Query.hs index 130d1eeff..470b842ab 100644 --- a/hledger-lib/Hledger/Query.hs +++ b/hledger-lib/Hledger/Query.hs @@ -828,7 +828,16 @@ matchesPostingExtra :: (AccountName -> Maybe AccountType) -> Query -> Posting -> matchesPostingExtra atype (Not q ) p = not $ matchesPostingExtra atype q p matchesPostingExtra atype (Or qs) p = any (\q -> matchesPostingExtra atype q p) qs matchesPostingExtra atype (And qs) p = all (\q -> matchesPostingExtra atype q p) qs -matchesPostingExtra atype (Type ts) p = maybe False (\t -> any (t `isAccountSubtypeOf`) ts) . atype $ paccount p +matchesPostingExtra atype (Type ts) p = + -- does posting's account's type, if we can detect it, match any of the given types ? + (maybe False (\t -> any (t `isAccountSubtypeOf`) ts) . atype $ paccount p) + -- or, try the same test with the original (pre-aliasing/pivoting) posting's account + || (fromMaybe False $ do + porig <- poriginal p + let a = paccount porig + t <- atype a + Just $ any (t `isAccountSubtypeOf`) ts + ) matchesPostingExtra _ q p = matchesPosting q p -- | Does the match expression match this transaction ?