From b9d33a42940ee721aed53ec96d8f7475f0f8caa4 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 13 Feb 2021 08:09:45 -0800 Subject: [PATCH] bs: just declaring a Cash account no longer hides Asset accounts Since Cash is also an Asset, declaring an account as Cash also disabled the fallback regexp for Asset accounts. --- hledger-lib/Hledger/Data/Journal.hs | 15 ++++++++++----- hledger/test/journal/account-types.test | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index dc4fcf5e8..66bc2094c 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -328,7 +328,11 @@ journalAccountNameTree = accountNameTreeFrom . journalAccountNames -- or otherwise for accounts with names matched by the case-insensitive -- regular expression @^assets?(:|$)@. journalAssetAccountQuery :: Journal -> Query -journalAssetAccountQuery = journalAccountTypeQuery [Asset,Cash] (toRegexCI' "^assets?(:|$)") +journalAssetAccountQuery j = + Or [ + journalAccountTypeQuery [Asset] (toRegexCI' "^assets?(:|$)") j + ,journalCashAccountQuery j + ] -- | A query for "Cash" (liquid asset) accounts in this journal, ie accounts -- declared as Cash by account directives, or otherwise with names matched by the @@ -384,13 +388,14 @@ journalProfitAndLossAccountQuery j = Or [journalRevenueAccountQuery j ,journalExpenseAccountQuery j ] --- | Get a query for accounts of the specified types (Asset, Liability..) in this journal. +-- | Get a query for accounts of the specified types in this journal. +-- Account types include Asset, Liability, Equity, Revenue, Expense, Cash. -- The query will match all accounts which were declared as one of -- these types by account directives, plus all their subaccounts which -- have not been declared as some other type. --- Or if no accounts were declared with these types, the query will --- instead match accounts with names matched by the provided --- case-insensitive regular expression. +-- For each type, if no accounts were declared with this type, the query +-- will instead match accounts with names matched by the case-insensitive +-- regular expression provided as a fallback. journalAccountTypeQuery :: [AccountType] -> Regexp -> Journal -> Query journalAccountTypeQuery atypes fallbackregex Journal{jdeclaredaccounttypes} = let diff --git a/hledger/test/journal/account-types.test b/hledger/test/journal/account-types.test index f0980415f..a36fa8f61 100644 --- a/hledger/test/journal/account-types.test +++ b/hledger/test/journal/account-types.test @@ -72,3 +72,26 @@ Income Statement 2020-01-01 || 1 ==========++============ Net: || 0 + +# 4. Just declaring a Cash account should not disable the fallback +# regexp for Asset accounts. +< +account assets ; +account assets:cash ; type:Cash + +2021-01-01 + (assets) 1 + (assets:cash) 1 + +$ hledger -f- bs -N +Balance Sheet 2021-01-01 + + || 2021-01-01 +=============++============ + Assets || +-------------++------------ + assets || 1 + assets:cash || 1 +=============++============ + Liabilities || +-------------++------------