From f54e3299b90c66703775b67c4d2aef6e8c45bdc4 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 4 Dec 2012 01:07:04 +0000 Subject: [PATCH] 94: fix 0.19 regression showing wrong total balance with balance --flat and distinguish better between account depth and item indent level --- hledger-lib/Hledger/Reports.hs | 10 +++++----- tests/94.test | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 tests/94.test diff --git a/hledger-lib/Hledger/Reports.hs b/hledger-lib/Hledger/Reports.hs index edb6e4391..038e88682 100644 --- a/hledger-lib/Hledger/Reports.hs +++ b/hledger-lib/Hledger/Reports.hs @@ -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 diff --git a/tests/94.test b/tests/94.test new file mode 100644 index 000000000..c7ac647e8 --- /dev/null +++ b/tests/94.test @@ -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 +