diff --git a/hledger-lib/Hledger/Reports/MultiBalanceReport.hs b/hledger-lib/Hledger/Reports/MultiBalanceReport.hs index 4acba4e20..442f25c80 100644 --- a/hledger-lib/Hledger/Reports/MultiBalanceReport.hs +++ b/hledger-lib/Hledger/Reports/MultiBalanceReport.hs @@ -344,7 +344,7 @@ displayedAccounts :: ReportOpts -> Query -> HashMap AccountName [Account] -> HashMap AccountName DisplayName displayedAccounts ropts q valuedaccts - | depth == 0 = HM.singleton "..." $ DisplayName "..." "..." 0 + | depth == 0 = HM.singleton "..." $ DisplayName "..." "..." 1 | otherwise = HM.mapWithKey (\a _ -> displayedName a) displayedAccts where -- Accounts which are to be displayed @@ -352,19 +352,18 @@ displayedAccounts ropts q valuedaccts where keep name amts = isInteresting name amts || name `HM.member` interestingParents - isDisplayed = (`HM.member` displayedAccts) - displayedName name - | flat_ ropts = DisplayName name droppedName 0 - | otherwise = DisplayName name leaf d + | flat_ ropts = DisplayName name droppedName 1 + | otherwise = DisplayName name leaf $ level - boringParents where - leaf = accountNameFromComponents . reverse . map accountLeafName $ - droppedName : takeWhile (not . isDisplayed) parents - d | no_elide_ ropts = accountNameLevel droppedName - | otherwise = accountNameLevel droppedName - length boringParents - boringParents = filter (not . isDisplayed) parents - parents = parentAccountNames droppedName droppedName = accountNameDrop (drop_ ropts) name + leaf = accountNameFromComponents . reverse . map accountLeafName $ + droppedName : takeWhile notDisplayed parents + + level = accountNameLevel name - drop_ ropts + parents = take (level - 1) $ parentAccountNames name + boringParents = if no_elide_ ropts then 0 else length $ filter notDisplayed parents + notDisplayed = not . (`HM.member` displayedAccts) -- Accounts interesting for their own sake isInteresting name amts = diff --git a/hledger-lib/Hledger/Reports/ReportTypes.hs b/hledger-lib/Hledger/Reports/ReportTypes.hs index 1d4084d20..e4ee6541f 100644 --- a/hledger-lib/Hledger/Reports/ReportTypes.hs +++ b/hledger-lib/Hledger/Reports/ReportTypes.hs @@ -139,14 +139,15 @@ instance ToJSON DisplayName where toEncoding = toEncoding . displayFull -- | Construct a flat display name, where the full name is also displayed at --- depth 0 +-- depth 1 flatDisplayName :: AccountName -> DisplayName -flatDisplayName a = DisplayName a a 0 +flatDisplayName a = DisplayName a a 1 -- | Construct a tree display name, where only the leaf is displayed at its -- given depth treeDisplayName :: AccountName -> DisplayName treeDisplayName a = DisplayName a (accountLeafName a) (accountNameLevel a) + -- | Get the full, canonical, name of a PeriodicReportRow tagged by a -- DisplayName. prrFullName :: PeriodicReportRow DisplayName a -> AccountName diff --git a/tests/balance/drop.test b/tests/balance/drop.test new file mode 100644 index 000000000..0b97327d1 --- /dev/null +++ b/tests/balance/drop.test @@ -0,0 +1,43 @@ +# 1. Drop works in flat mode +< +2018/1/1 + (b:j) 1 + +2018/1/1 + (b:j:q) 1 + +2018/1/1 + (c) 1 + +2018/1/1 + (b:i:p) 1 + +2018/1/1 + (a:k) 1 + +$ hledger -f - balance --flat --no-total --drop 1 + 1 k + 1 i:p + 1 j + 1 j:q + 1 ... +>= + +## 2. Drop works in tree mode with no boring parent ellision +$ hledger -f - balance --tree --no-elide --no-total --drop 1 + 1 k + 1 i + 1 p + 2 j + 1 q + 1 ... +>= + +## 3. Drop works in tree mode with boring parent ellision +$ hledger -f - balance --tree --no-total --drop 1 + 1 k + 1 i:p + 2 j + 1 q + 1 ... +>=