94: fix 0.19 regression showing wrong total balance with balance --flat

and distinguish better between account depth and item indent level
This commit is contained in:
Simon Michael 2012-12-04 01:07:04 +00:00
parent 00b4efffc9
commit f54e3299b9
2 changed files with 36 additions and 5 deletions

View File

@ -531,7 +531,7 @@ type AccountsReport = ([AccountsReportItem] -- line items, one per account
)
type AccountsReportItem = (AccountName -- full account name
,AccountName -- short account name for display (the leaf name, prefixed by any boring parents immediately above)
,Int -- how many steps to indent this account (0-based account depth excluding boring parents)
,Int -- how many steps to indent this account (0 with --flat, otherwise the 0-based account depth excluding boring parents)
,MixedAmount) -- account balance, includes subs unless --flat is present
-- | Select accounts, and get their balances at the end of the selected
@ -552,7 +552,7 @@ accountsReport opts q j = (items, total)
markboring | no_elide_ opts = id
| otherwise = markBoringParentAccounts
items = map (accountsReportItem opts) accts'
total = sum [amt | (_,_,depth,amt) <- items, depth==0]
total = sum [amt | (a,_,_,amt) <- items, accountNameLevel a == 1]
-- | In an account tree with zero-balance leaves removed, mark the
-- elidable parent accounts (those with one subaccount and no balance
@ -565,12 +565,12 @@ markBoringParentAccounts = tieAccountParents . mapAccounts mark
accountsReportItem :: ReportOpts -> Account -> AccountsReportItem
accountsReportItem opts a@Account{aname=name, aibalance=ibal}
| flat_ opts = (name, name, 0, ibal)
| otherwise = (name, elidedname, depth, ibal)
| flat_ opts = (name, name, 0, ibal)
| otherwise = (name, elidedname, indent, ibal)
where
elidedname = accountNameFromComponents (adjacentboringparentnames ++ [accountLeafName name])
adjacentboringparentnames = reverse $ map (accountLeafName.aname) $ takeWhile aboring $ parents
depth = length $ filter (not.aboring) parents
indent = length $ filter (not.aboring) parents
parents = init $ parentAccounts a

31
tests/94.test Normal file
View File

@ -0,0 +1,31 @@
# issue 94: total balance should be that of top-level accounts, with and without --flat
# 1.
hledgerdev -f - balance
<<<
1/1
(a) 1
1/1
(a:aa) 1
>>>
2 a
1 aa
--------------------
2
>>>= 0
# 2.
hledgerdev -f - balance --flat
<<<
1/1
(a) 1
1/1
(a:aa) 1
>>>
2 a
1 a:aa
--------------------
2
>>>= 0