Skip to content

Commit

Permalink
imp: balcmds: support --declared on bs/cf/is also (#1765)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichael committed Nov 25, 2021
1 parent 6319d61 commit 7f320eb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
14 changes: 8 additions & 6 deletions hledger-lib/Hledger/Reports/MultiBalanceReport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hledger/Hledger/Cli/Commands/Balance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
1 change: 1 addition & 0 deletions hledger/Hledger/Cli/CompoundBalanceCommand.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 23 additions & 0 deletions hledger/test/incomestatement.test
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7f320eb

Please sign in to comment.