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.
This commit is contained in:
Simon Michael 2021-02-13 08:09:45 -08:00
parent 50bfc26ca7
commit b9d33a4294
2 changed files with 33 additions and 5 deletions

View File

@ -328,7 +328,11 @@ journalAccountNameTree = accountNameTreeFrom . journalAccountNames
-- or otherwise for accounts with names matched by the case-insensitive -- or otherwise for accounts with names matched by the case-insensitive
-- regular expression @^assets?(:|$)@. -- regular expression @^assets?(:|$)@.
journalAssetAccountQuery :: Journal -> Query 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 -- | 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 -- declared as Cash by account directives, or otherwise with names matched by the
@ -384,13 +388,14 @@ journalProfitAndLossAccountQuery j = Or [journalRevenueAccountQuery j
,journalExpenseAccountQuery 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 -- The query will match all accounts which were declared as one of
-- these types by account directives, plus all their subaccounts which -- these types by account directives, plus all their subaccounts which
-- have not been declared as some other type. -- have not been declared as some other type.
-- Or if no accounts were declared with these types, the query will -- For each type, if no accounts were declared with this type, the query
-- instead match accounts with names matched by the provided -- will instead match accounts with names matched by the case-insensitive
-- case-insensitive regular expression. -- regular expression provided as a fallback.
journalAccountTypeQuery :: [AccountType] -> Regexp -> Journal -> Query journalAccountTypeQuery :: [AccountType] -> Regexp -> Journal -> Query
journalAccountTypeQuery atypes fallbackregex Journal{jdeclaredaccounttypes} = journalAccountTypeQuery atypes fallbackregex Journal{jdeclaredaccounttypes} =
let let

View File

@ -72,3 +72,26 @@ Income Statement 2020-01-01
|| 1 || 1
==========++============ ==========++============
Net: || 0 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 ||
-------------++------------