cli: compoundbalancecommand keeps zero-balance accounts with children
This commit is contained in:
		
							parent
							
								
									a6a73e36e3
								
							
						
					
					
						commit
						15c666702b
					
				| @ -14,7 +14,7 @@ module Hledger.Cli.CompoundBalanceCommand ( | ||||
| ) where | ||||
| 
 | ||||
| import Data.List (foldl') | ||||
| import Data.Maybe (fromMaybe) | ||||
| import Data.Maybe (fromMaybe,catMaybes) | ||||
| import qualified Data.Text as TS | ||||
| import qualified Data.Text.Lazy as TL | ||||
| import System.Console.CmdArgs.Explicit as C | ||||
| @ -218,13 +218,19 @@ compoundBalanceSubreport ropts userq j subreportqfn subreportnormalsign = r' | ||||
|     -- run the report | ||||
|     q = And [subreportqfn j, userq] | ||||
|     r@(MultiBalanceReport (dates, rows, totals)) = multiBalanceReport ropts' q j | ||||
|     -- if user didn't specify --empty, now remove the all-zero rows | ||||
|     -- if user didn't specify --empty, now remove the all-zero rows, unless they have non-zero subaccounts | ||||
|     -- in this report | ||||
|     r' | empty_ ropts = r | ||||
|        | otherwise    = MultiBalanceReport (dates, rows', totals)  | ||||
|           where | ||||
|             nonzeroaccounts = | ||||
|               dbg1 "nonzeroaccounts" $ | ||||
|               catMaybes $ map (\(act,_,_,amts,_,_) -> | ||||
|                             if not (all isZeroMixedAmount amts) then Just act else Nothing) rows  | ||||
|             rows' = filter (not . emptyRow) rows | ||||
|               where | ||||
|                 emptyRow (_,_,_,amts,_,_) = all isZeroMixedAmount amts | ||||
|                 emptyRow (act,_,_,amts,_,_) = | ||||
|                   all isZeroMixedAmount amts && all (not . (act `isAccountNamePrefixOf`)) nonzeroaccounts | ||||
| 
 | ||||
| -- | Render a compound balance report as plain text suitable for console output. | ||||
| {- Eg: | ||||
|  | ||||
| @ -241,3 +241,44 @@ Balance Sheet 2016/01/01 | ||||
|  Net:        ║          1  | ||||
| >>>2 | ||||
| >>>= 0 | ||||
| 
 | ||||
| # 10. Check that accounts brought to zero by subaccount balances | ||||
| # are not erased from balancesheet | ||||
| hledger -f - balancesheet | ||||
| <<< | ||||
| 2018-10-01 | ||||
|    income:whatever | ||||
|    assets:bank      $100 | ||||
|    assets:bank:subaccount  $10 | ||||
|    assets:bank:this subaccount should disappear  $10 | ||||
| 
 | ||||
| 2018-10-02 | ||||
|    assets:bank:this subaccount should disappear  -$10 | ||||
|    assets:bank | ||||
| 
 | ||||
| 2018-10-03 | ||||
|    assets:this account should not disappear:subaccount   -$10 | ||||
|    assets:this account should not disappear | ||||
| >>> | ||||
| Balance Sheet 2018/10/01-2018/10/03 | ||||
| 
 | ||||
|                                      || 2018/10/03  | ||||
| =====================================++============ | ||||
|  Assets                              ||             | ||||
| -------------------------------------++------------ | ||||
|  assets                              ||       $120  | ||||
|    bank                              ||       $120  | ||||
|      subaccount                      ||        $10  | ||||
|    this account should not disappear ||          0  | ||||
|      subaccount                      ||       $-10  | ||||
| -------------------------------------++------------ | ||||
|                                      ||       $120  | ||||
| =====================================++============ | ||||
|  Liabilities                         ||             | ||||
| -------------------------------------++------------ | ||||
| -------------------------------------++------------ | ||||
|                                      ||             | ||||
| =====================================++============ | ||||
|  Net:                                ||       $120  | ||||
| >>>2 | ||||
| >>>= 0 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user