fix: balance: Clip account names in generateMultiBalanceAccount, not before (#2434)
Previously accounts were clipped in getPostings, however compound balance reports re-use the output of getPostings for the different subreports. This caused a problem when clipping erased the information needed to determine the account type, as would be used by e.g. incomestatement. Add some extra tests for --count.
This commit is contained in:
parent
b5cb1d08d0
commit
ef5c220690
@ -143,9 +143,10 @@ compoundBalanceReportWith rspec' j priceoracle subreportspecs = cbr
|
|||||||
-- Add a restriction to this subreport to the report query.
|
-- Add a restriction to this subreport to the report query.
|
||||||
-- XXX in non-thorough way, consider updateReportSpec ?
|
-- XXX in non-thorough way, consider updateReportSpec ?
|
||||||
rspecsub = rspec{_rsReportOpts=ropts, _rsQuery=And [cbcsubreportquery, _rsQuery rspec]}
|
rspecsub = rspec{_rsReportOpts=ropts, _rsQuery=And [cbcsubreportquery, _rsQuery rspec]}
|
||||||
|
-- Match and postings for the subreport
|
||||||
|
subreportps = filter (matchesPostingExtra (journalAccountType j) cbcsubreportquery) ps
|
||||||
-- Account representing this subreport
|
-- Account representing this subreport
|
||||||
acct = generateMultiBalanceAccount rspecsub j priceoracle colspans $
|
acct = generateMultiBalanceAccount rspecsub j priceoracle colspans subreportps
|
||||||
filter (matchesPostingExtra (journalAccountType j) cbcsubreportquery) ps
|
|
||||||
|
|
||||||
-- Sum the subreport totals by column. Handle these cases:
|
-- Sum the subreport totals by column. Handle these cases:
|
||||||
-- - no subreports
|
-- - no subreports
|
||||||
@ -178,14 +179,10 @@ makeReportQuery rspec reportspan
|
|||||||
-- | Gather postings matching the query within the report period.
|
-- | Gather postings matching the query within the report period.
|
||||||
getPostings :: ReportSpec -> Journal -> PriceOracle -> DateSpan -> [Posting]
|
getPostings :: ReportSpec -> Journal -> PriceOracle -> DateSpan -> [Posting]
|
||||||
getPostings rspec@ReportSpec{_rsQuery=query, _rsReportOpts=ropts} j priceoracle reportspan =
|
getPostings rspec@ReportSpec{_rsQuery=query, _rsReportOpts=ropts} j priceoracle reportspan =
|
||||||
map clipPosting
|
setPostingsCount
|
||||||
. setPostingsCount
|
|
||||||
. journalPostings
|
. journalPostings
|
||||||
$ journalValueAndFilterPostingsWith rspec' j priceoracle
|
$ journalValueAndFilterPostingsWith rspec' j priceoracle
|
||||||
where
|
where
|
||||||
-- Clip posting names to the requested depth
|
|
||||||
clipPosting p = p{paccount = clipOrEllipsifyAccountName depthSpec $ paccount p}
|
|
||||||
|
|
||||||
-- If doing --count, set all posting amounts to "1".
|
-- If doing --count, set all posting amounts to "1".
|
||||||
setPostingsCount = case balancecalc_ ropts of
|
setPostingsCount = case balancecalc_ ropts of
|
||||||
CalcPostingsCount -> map (postingTransformAmount (const $ mixed [num 1]))
|
CalcPostingsCount -> map (postingTransformAmount (const $ mixed [num 1]))
|
||||||
@ -209,8 +206,6 @@ getPostings rspec@ReportSpec{_rsQuery=query, _rsReportOpts=ropts} j priceoracle
|
|||||||
-- handles the hledger-ui+future txns case above).
|
-- handles the hledger-ui+future txns case above).
|
||||||
depthlessq = dbg3 "getPostings depthlessq" $ filterQuery (not . queryIsDepth) query
|
depthlessq = dbg3 "getPostings depthlessq" $ filterQuery (not . queryIsDepth) query
|
||||||
|
|
||||||
depthSpec = dbg3 "getPostings depthSpec" . queryDepth $ filterQuery queryIsDepth query
|
|
||||||
|
|
||||||
fullreportspan = if requiresHistorical ropts then DateSpan Nothing (Exact <$> spanEnd reportspan) else reportspan
|
fullreportspan = if requiresHistorical ropts then DateSpan Nothing (Exact <$> spanEnd reportspan) else reportspan
|
||||||
fullreportspanq = (if date2_ ropts then Date2 else Date) $ case fullreportspan of
|
fullreportspanq = (if date2_ ropts then Date2 else Date) $ case fullreportspan of
|
||||||
DateSpan Nothing Nothing -> emptydatespan
|
DateSpan Nothing Nothing -> emptydatespan
|
||||||
@ -230,6 +225,13 @@ generateMultiBalanceAccount rspec@ReportSpec{_rsReportOpts=ropts} j priceoracle
|
|||||||
. mapAccounts (accountSetDeclarationInfo j)
|
. mapAccounts (accountSetDeclarationInfo j)
|
||||||
-- Process changes into normal, cumulative, or historical amounts, plus value them
|
-- Process changes into normal, cumulative, or historical amounts, plus value them
|
||||||
. calculateReportAccount rspec j priceoracle colspans
|
. calculateReportAccount rspec j priceoracle colspans
|
||||||
|
-- Clip account names
|
||||||
|
. map clipPosting
|
||||||
|
where
|
||||||
|
-- Clip postings to the requested depth according to the query
|
||||||
|
clipPosting p = p{paccount = clipOrEllipsifyAccountName depthSpec $ paccount p}
|
||||||
|
depthSpec = dbg3 "generateMultiBalanceAccount depthSpec"
|
||||||
|
. queryDepth . filterQuery queryIsDepth $ _rsQuery rspec
|
||||||
|
|
||||||
-- | Add declared accounts to the account tree.
|
-- | Add declared accounts to the account tree.
|
||||||
addDeclaredAccounts :: Monoid a => ReportSpec -> Journal -> Account a -> Account a
|
addDeclaredAccounts :: Monoid a => ReportSpec -> Journal -> Account a -> Account a
|
||||||
|
|||||||
@ -201,13 +201,29 @@ $ hledger -f- bal -MT -O html
|
|||||||
a 10
|
a 10
|
||||||
a:aa 20
|
a:aa 20
|
||||||
b
|
b
|
||||||
|
$ hledger -f- bal --count
|
||||||
|
1 a
|
||||||
|
1 a:aa
|
||||||
|
1 b
|
||||||
|
--------------------
|
||||||
|
3
|
||||||
|
|
||||||
|
# ** 16. --count counts clipped postings.
|
||||||
$ hledger -f- bal --count -1
|
$ hledger -f- bal --count -1
|
||||||
2 a
|
2 a
|
||||||
1 b
|
1 b
|
||||||
--------------------
|
--------------------
|
||||||
3
|
3
|
||||||
|
|
||||||
# ** 16. Make sure that balance --flat --empty does not display implied
|
# ** 17. --count counts inclusive postings with --tree.
|
||||||
|
$ hledger -f- bal --count --tree
|
||||||
|
2 a
|
||||||
|
1 aa
|
||||||
|
1 b
|
||||||
|
--------------------
|
||||||
|
3
|
||||||
|
|
||||||
|
# ** 18. Make sure that balance --flat --empty does not display implied
|
||||||
# accounts (i.e. those with no postings, like "assets", here), but does show
|
# accounts (i.e. those with no postings, like "assets", here), but does show
|
||||||
# accounts that have postings with zero balance (like "assets:bank:checking"
|
# accounts that have postings with zero balance (like "assets:bank:checking"
|
||||||
# here).
|
# here).
|
||||||
|
|||||||
@ -304,3 +304,29 @@ Income Statement ..
|
|||||||
Expenses ||
|
Expenses ||
|
||||||
-----------------++----
|
-----------------++----
|
||||||
expenses || 0
|
expenses || 0
|
||||||
|
|
||||||
|
# ** 10. Clipping too far doesn't erase account types (#2434)
|
||||||
|
<
|
||||||
|
account sm:assets ; type:A
|
||||||
|
account sm:revenues ; type:R
|
||||||
|
|
||||||
|
2025-01-01
|
||||||
|
sm:revenues -$1
|
||||||
|
sm:assets $1
|
||||||
|
|
||||||
|
2025-01-02
|
||||||
|
sm:revenues A -2
|
||||||
|
sm:assets A 2
|
||||||
|
|
||||||
|
$ hledger -f - incomestatement -1 -N
|
||||||
|
Income Statement 2025-01-01..2025-01-02
|
||||||
|
|
||||||
|
|| 2025-01-01..2025-01-02
|
||||||
|
==========++========================
|
||||||
|
Revenues ||
|
||||||
|
----------++------------------------
|
||||||
|
sm || $1, A 2
|
||||||
|
==========++========================
|
||||||
|
Expenses ||
|
||||||
|
----------++------------------------
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user