diff --git a/Ledger/Entry.hs b/Ledger/Entry.hs index 82367cedb..ad60e2d63 100644 --- a/Ledger/Entry.hs +++ b/Ledger/Entry.hs @@ -49,7 +49,7 @@ pcommentwidth = no limit -- 22 -} showEntry :: Entry -> String showEntry e = - unlines $ [precedingcomment ++ description] ++ (showtxns $ etransactions e) ++ [""] + unlines $ [{-precedingcomment ++ -}description] ++ (showtxns $ etransactions e) ++ [""] where precedingcomment = epreceding_comment_lines e description = concat [date, status, code, desc] -- , comment] diff --git a/Ledger/RawLedger.hs b/Ledger/RawLedger.hs index ffcb0f42d..a15d329cb 100644 --- a/Ledger/RawLedger.hs +++ b/Ledger/RawLedger.hs @@ -50,7 +50,7 @@ filterRawLedger begin end pats clearedonly realonly = filterRawLedgerEntriesByDate begin end . filterRawLedgerEntriesByDescription pats --- | Keep only entries whose description matches the description pattern. +-- | Keep only entries whose description matches the description patterns. filterRawLedgerEntriesByDescription :: [String] -> RawLedger -> RawLedger filterRawLedgerEntriesByDescription pats (RawLedger ms ps es f) = RawLedger ms ps (filter matchdesc es) f @@ -80,6 +80,11 @@ filterRawLedgerTransactionsByRealness True (RawLedger ms ps es f) = RawLedger ms ps (map filtertxns es) f where filtertxns e@Entry{etransactions=ts} = e{etransactions=filter isReal ts} +-- | Keep only entries which affect accounts matched by the account patterns. +filterRawLedgerEntriesByAccount :: [String] -> RawLedger -> RawLedger +filterRawLedgerEntriesByAccount apats (RawLedger ms ps es f) = + RawLedger ms ps (filter (any (matchpats apats . taccount) . etransactions) es) f + -- | Give all a ledger's amounts their canonical display settings. That -- is, in each commodity, amounts will use the display settings of the -- first amount detected, and the greatest precision of the amounts diff --git a/NOTES b/NOTES index 8aea4ff83..333d55fea 100644 --- a/NOTES +++ b/NOTES @@ -6,8 +6,6 @@ implementations were its consequences." --Niklaus Wirth * to do ** errors -*** make account balances reflect account filtering -*** print command doesn't filter by account ? *** ? in description or amount gives "too many blank transactions" *** parse commented lines at end of file *** display mixed amounts vertically, not horizontally @@ -67,6 +65,7 @@ implementations were its consequences." --Niklaus Wirth *** ledger shows description comments as part of description *** ledger shows small time amounts in minutes *** ledger can get timelog entry balance wrong, see mail list +*** hledger print puts a blank line after the entry, not before it ** things I want to know *** time where have I been spending my time in recent weeks ? diff --git a/PrintCommand.hs b/PrintCommand.hs index 9c6b2375a..ce99e6164 100644 --- a/PrintCommand.hs +++ b/PrintCommand.hs @@ -15,4 +15,7 @@ print' :: [Opt] -> [String] -> Ledger -> IO () print' opts args l = putStr $ showEntries opts args l showEntries :: [Opt] -> [String] -> Ledger -> String -showEntries opts args l = concatMap showEntry $ entries $ rawledger l +showEntries opts args l = concatMap showEntry $ filteredentries + where + filteredentries = entries $ filterRawLedgerEntriesByAccount apats $ rawledger l + (apats,_) = parseAccountDescriptionArgs args diff --git a/Tests.hs b/Tests.hs index 28f8dfe8d..b5f74a53e 100644 --- a/Tests.hs +++ b/Tests.hs @@ -30,6 +30,7 @@ tests = [TestList [] ,misc_tests ,balancereportacctnames_tests ,balancecommand_tests + ,printcommand_tests ,registercommand_tests ] @@ -271,6 +272,20 @@ balancecommand_tests = TestList [ l <- ledgerfromfile pats "sample.ledger" assertequal e (showBalanceReport opts pats l) +printcommand_tests = TestList [ + "print with account patterns" ~: + do + let pats = ["expenses"] + l <- ledgerfromfile pats "sample.ledger" + assertequal ( + "2007/01/01 * eat & shop\n" ++ + " expenses:food $1\n" ++ + " expenses:supplies $1\n" ++ + " assets:cash $-2\n" ++ + "\n") + $ showEntries [] pats l + ] + registercommand_tests = TestList [ "register report" ~: do