diff --git a/Options.hs b/Options.hs index 73b522984..b3af69ae8 100644 --- a/Options.hs +++ b/Options.hs @@ -192,9 +192,9 @@ intervalFromOpts opts -- doesn't affect the interval, but parsePeriodExpr needs something refdate = parsedate "0001/01/01" --- | Get the value of the (last) depth option, if any. -depthFromOpts :: [Opt] -> Maybe Int -depthFromOpts opts = listtomaybeint $ optValuesForConstructor Depth opts +-- | Get the value of the (last) depth option, if any, otherwise a large number. +depthFromOpts :: [Opt] -> Int +depthFromOpts opts = fromMaybe 9999 $ listtomaybeint $ optValuesForConstructor Depth opts where listtomaybeint [] = Nothing listtomaybeint vs = Just $ read $ last vs diff --git a/RegisterCommand.hs b/RegisterCommand.hs index 70562ebbc..a61a242da 100644 --- a/RegisterCommand.hs +++ b/RegisterCommand.hs @@ -70,7 +70,7 @@ showRegisterReport opts args l -- -- The showempty flag forces the display of a zero-transaction span -- and also zero-transaction accounts within the span. -summariseTransactionsInDateSpan :: DateSpan -> Int -> Maybe Int -> Bool -> [Transaction] -> [Transaction] +summariseTransactionsInDateSpan :: DateSpan -> Int -> Int -> Bool -> [Transaction] -> [Transaction] summariseTransactionsInDateSpan (DateSpan b e) entryno depth showempty ts | null ts && showempty = [txn] | null ts = [] @@ -86,14 +86,13 @@ summariseTransactionsInDateSpan (DateSpan b e) entryno depth showempty ts -- aggregate balances by account, like cacheLedger, then do depth-clipping (_,_,exclbalof,inclbalof) = groupTransactions ts clippedanames = clipAccountNames depth txnanames - isclipped a = accountNameLevel a >= fromMaybe 9999 depth + isclipped a = accountNameLevel a >= depth balancetoshowfor a = (if isclipped a then inclbalof else exclbalof) (if null a then "top" else a) summaryts = [txn{account=a,amount=balancetoshowfor a} | a <- clippedanames] -clipAccountNames :: Maybe Int -> [AccountName] -> [AccountName] -clipAccountNames Nothing as = as -clipAccountNames (Just d) as = nub $ map (clip d) as +clipAccountNames :: Int -> [AccountName] -> [AccountName] +clipAccountNames d as = nub $ map (clip d) as where clip d = accountNameFromComponents . take d . accountNameComponents -- | Does the given transaction fall within the given date span ? diff --git a/Tests.hs b/Tests.hs index d975457e5..fddb5a36f 100644 --- a/Tests.hs +++ b/Tests.hs @@ -683,27 +683,27 @@ tests = [ ,nulltxn{description="desc",account="expenses:food", amount=Mixed [dollars 4]} ,nulltxn{description="desc",account="expenses:food:dining", amount=Mixed [dollars 8]} ] - ("2008/01/01","2009/01/01",0,Nothing,False,[]) `gives` + ("2008/01/01","2009/01/01",0,9999,False,[]) `gives` [] - ("2008/01/01","2009/01/01",0,Nothing,True,[]) `gives` + ("2008/01/01","2009/01/01",0,9999,True,[]) `gives` [ nulltxn{date=parsedate "2008/01/01",description="- 2008/12/31"} ] - ("2008/01/01","2009/01/01",0,Nothing,False,ts) `gives` + ("2008/01/01","2009/01/01",0,9999,False,ts) `gives` [ nulltxn{date=parsedate "2008/01/01",description="- 2008/12/31",account="expenses:food", amount=Mixed [dollars 4]} ,nulltxn{date=parsedate "2008/01/01",description="- 2008/12/31",account="expenses:food:dining", amount=Mixed [dollars 10]} ,nulltxn{date=parsedate "2008/01/01",description="- 2008/12/31",account="expenses:food:groceries",amount=Mixed [dollars 1]} ] - ("2008/01/01","2009/01/01",0,Just 2,False,ts) `gives` + ("2008/01/01","2009/01/01",0,2,False,ts) `gives` [ nulltxn{date=parsedate "2008/01/01",description="- 2008/12/31",account="expenses:food",amount=Mixed [dollars 15]} ] - ("2008/01/01","2009/01/01",0,Just 1,False,ts) `gives` + ("2008/01/01","2009/01/01",0,1,False,ts) `gives` [ nulltxn{date=parsedate "2008/01/01",description="- 2008/12/31",account="expenses",amount=Mixed [dollars 15]} ] - ("2008/01/01","2009/01/01",0,Just 0,False,ts) `gives` + ("2008/01/01","2009/01/01",0,0,False,ts) `gives` [ nulltxn{date=parsedate "2008/01/01",description="- 2008/12/31",account="",amount=Mixed [dollars 15]} ]