bs/is: don't let an empty subreport disable the grand totals (fixes #588)
This commit is contained in:
		
							parent
							
								
									083df72582
								
							
						
					
					
						commit
						c89bec0e17
					
				| @ -140,8 +140,14 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} CliOpts{command_=cmd, repo | |||||||
|                 row "Total" overalltotals' |                 row "Total" overalltotals' | ||||||
|               where |               where | ||||||
|                 overalltotals = case subreporttotals of |                 overalltotals = case subreporttotals of | ||||||
|                   a1:as -> foldl' (zipWith (+)) a1 as |                   [] -> [] | ||||||
|                   []    -> [] |                   ts -> foldl' (zipWith (+)) zeros ts' | ||||||
|  |                     where | ||||||
|  |                       -- A subreport might be empty and have no subtotals, count those as zeroes (#588). | ||||||
|  |                       -- Varying-length subtotals rows are handled similarly, though that is not expected to happen.   | ||||||
|  |                       len = maximum $ map length ts | ||||||
|  |                       ts' = [take len $ as ++ repeat nullmixedamt | as <- ts] | ||||||
|  |                       zeros = replicate len nullmixedamt | ||||||
|                 overalltotals' |                 overalltotals' | ||||||
|                   | null overalltotals = [] |                   | null overalltotals = [] | ||||||
|                   | otherwise =  overalltotals |                   | otherwise =  overalltotals | ||||||
|  | |||||||
| @ -174,3 +174,29 @@ Total: | |||||||
| >>>2 | >>>2 | ||||||
| >>>=0 | >>>=0 | ||||||
| 
 | 
 | ||||||
|  | # 8. An empty section is does not disrupt the overall totals, #588 | ||||||
|  | hledger -f- balancesheet -YTA | ||||||
|  | <<< | ||||||
|  | 2017/1/1 | ||||||
|  |   (assets)  $1 | ||||||
|  | >>> | ||||||
|  | Balance Sheet | ||||||
|  | 
 | ||||||
|  |              ||  2017/12/31    Total  Average  | ||||||
|  | =============++=============================== | ||||||
|  |  Assets      ||                                | ||||||
|  | -------------++------------------------------- | ||||||
|  |  assets      ||          $1       $1       $1  | ||||||
|  | -------------++------------------------------- | ||||||
|  |              ||          $1       $1       $1  | ||||||
|  | =============++=============================== | ||||||
|  |  Liabilities ||                                | ||||||
|  | -------------++------------------------------- | ||||||
|  | -------------++------------------------------- | ||||||
|  |              ||                                | ||||||
|  | =============++=============================== | ||||||
|  |  Total       ||          $1       $1       $1  | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | >>>2 | ||||||
|  | >>>=0 | ||||||
|  | |||||||
| @ -20,7 +20,7 @@ Balance Sheet | |||||||
| ─────────────╫───────────── | ─────────────╫───────────── | ||||||
|              ║              |              ║              | ||||||
| ═════════════╬═════════════ | ═════════════╬═════════════ | ||||||
|  Total       ║              |  Total       ║           1  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| >>>2 | >>>2 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user