imp: balcmds: support --declared on bs/cf/is also (#1765)

This commit is contained in:
Simon Michael 2021-11-23 11:06:27 -10:00
parent 6319d6148f
commit 7f320ebfa9
4 changed files with 33 additions and 7 deletions

View File

@ -159,16 +159,18 @@ compoundBalanceReportWith rspec' j priceoracle subreportspecs = cbr
( cbcsubreporttitle
-- Postprocess the report, negating balances and taking percentages if needed
, cbcsubreporttransform $
generateMultiBalanceReport rspec{_rsReportOpts=ropts} j priceoracle colps' startbals'
generateMultiBalanceReport rspecsub j priceoracle colps' startbals'
, cbcsubreportincreasestotal
)
where
-- Filter the column postings according to each subreport
-- Add a restriction to this subreport to the report query.
-- XXX in non-thorough way, consider updateReportSpec ?
q = cbcsubreportquery j
ropts = cbcsubreportoptions $ _rsReportOpts rspec
rspecsub = rspec{_rsReportOpts=ropts, _rsQuery=And [q, _rsQuery rspec]}
-- Starting balances and column postings specific to this subreport.
startbals' = startingBalances rspecsub j priceoracle $ filter (matchesPosting q) startps
colps' = map (second $ filter (matchesPosting q)) colps
-- We need to filter historical postings directly, rather than their accumulated balances. (#1698)
startbals' = startingBalances rspec j priceoracle $ filter (matchesPosting q) startps
ropts = cbcsubreportoptions $ _rsReportOpts rspec
q = cbcsubreportquery j
-- Sum the subreport totals by column. Handle these cases:
-- - no subreports

View File

@ -308,7 +308,7 @@ balancemode = hledgerCommandMode
]
++ flattreeflags True ++
[flagReq ["drop"] (\s opts -> Right $ setopt "drop" s opts) "N" "omit N leading account name parts (in flat mode)"
,flagNone ["declared"] (setboolopt "declared") "include accounts which have been declared but not yet used"
,flagNone ["declared"] (setboolopt "declared") "include non-parent declared accounts (best used with -E)"
,flagNone ["average","A"] (setboolopt "average") "show a row average column (in multicolumn reports)"
,flagNone ["related","r"] (setboolopt "related") "show postings' siblings instead"
,flagNone ["row-total","T"] (setboolopt "row-total") "show a row total column (in multicolumn reports)"

View File

@ -77,6 +77,7 @@ compoundBalanceCommandMode CompoundBalanceCommandSpec{..} =
]
++ flattreeflags True ++
[flagReq ["drop"] (\s opts -> Right $ setopt "drop" s opts) "N" "flat mode: omit N leading account name parts"
,flagNone ["declared"] (setboolopt "declared") "include non-parent declared accounts (best used with -E)"
,flagNone ["average","A"] (setboolopt "average") "show a row average column (in multicolumn reports)"
,flagNone ["row-total","T"] (setboolopt "row-total") "show a row total column (in multicolumn reports)"
,flagNone ["no-total","N"] (setboolopt "no-total") "omit the final total row"

View File

@ -302,3 +302,26 @@ Income Statement 2008
expenses:supplies || 0 50.0 % 0 0 50.0 % 50.0 %
>>>= 0
# 9. With --declared, declared leaf accounts are included, and in the right place.
hledger -f - incomestatement -N -E --declared
<<<
account revenues
account revenues:aa
account revenues:ab
account revenues:ac:aca
account expenses
>>>
Income Statement ..
|| ..
=================++====
Revenues ||
-----------------++----
revenues:aa || 0
revenues:ab || 0
revenues:ac:aca || 0
=================++====
Expenses ||
-----------------++----
expenses || 0
>>>= 0