Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cf/bs/bse/is don't show child accounts if there is an intervening account of another type #1921

Closed
simonmichael opened this issue Aug 20, 2022 · 1 comment
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. balancesheet cashflow incomestatement

Comments

@simonmichael
Copy link
Owner

Reported by scara. Eg

account a         ; type:L
account a:aa      ; type:X
account a:aa:aaa  ; type:L

2021-01-01
    (a)                                            1
    (a:aa)                                         1
    (a:aa:aaa)                                     1
$ hledger bs
Balance Sheet 2021-01-01

             || 2021-01-01 
=============++============
 Assets      ||            
-------------++------------
-------------++------------
             ||            
=============++============
 Liabilities ||            
-------------++------------
 a           ||         -1 
-------------++------------
             ||         -1 
=============++============
 Net:        ||          1 

It should show a:aa:aaa as well (compare bal type:L and accounts --types. These commands need to be updated to use the newer account type queries.

-- | Get a query for accounts of the specified types in this journal.
-- Account types include:
-- Asset, Liability, Equity, Revenue, Expense, Cash, Conversion.
-- 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.
-- The query will match all accounts which were declared as one of
-- these types (by account directives with the type: tag), plus all their
-- subaccounts which have not been declared as some other type.
--
-- This is older code pre-dating 2022's expansion of account types.
journalAccountTypeQuery :: [AccountType] -> Regexp -> Journal -> Query
journalAccountTypeQuery atypes fallbackregex Journal{jdeclaredaccounttypes} =
let
declaredacctsoftype :: [AccountName] =
concat $ mapMaybe (`M.lookup` jdeclaredaccounttypes) atypes
in case declaredacctsoftype of
[] -> Acct fallbackregex
as -> And $ Or acctnameRegexes : if null differentlyTypedRegexes then [] else [ Not $ Or differentlyTypedRegexes ]
where
-- XXX Query isn't able to match account type since that requires extra info from the journal.
-- So we do a hacky search by name instead.
acctnameRegexes = map (Acct . accountNameToAccountRegex) as
differentlyTypedRegexes = map (Acct . accountNameToAccountRegex) differentlytypedsubs
differentlytypedsubs = concat
[subs | (t,bs) <- M.toList jdeclaredaccounttypes
, t `notElem` atypes
, let subs = [b | b <- bs, any (`isAccountNamePrefixOf` b) as]
]

@simonmichael simonmichael added A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. balancesheet incomestatement cashflow labels Aug 20, 2022
Xitian9 added a commit to Xitian9/hledger that referenced this issue Aug 20, 2022
This replaces the old journal*AccountQuery with the new Type query. This
enables uniform treatment of account type, and fixes a subtle bug
(simonmichael#1921).

Note that cbcsubreportquery no longer takes Journal as an argument.
Xitian9 added a commit to Xitian9/hledger that referenced this issue Aug 20, 2022
This replaces the old journal*AccountQuery with the new Type query. This
enables uniform treatment of account type, and fixes a subtle bug
(simonmichael#1921).

Note that cbcsubreportquery no longer takes Journal as an argument.
simonmichael pushed a commit that referenced this issue Aug 21, 2022
This replaces the old journal*AccountQuery with the new Type query. This
enables uniform treatment of account type, and fixes a subtle bug
(#1921).

Note that cbcsubreportquery no longer takes Journal as an argument.
@simonmichael
Copy link
Owner Author

Fixed by #1923.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. balancesheet cashflow incomestatement
Projects
None yet
Development

No branches or pull requests

1 participant