!imp: type: Change the default account inference for Cash accounts to only match
^assets?(:.+)?:(cash|bank|che(ck|que?)(ing)?|savings?|current)(:|$) This should have no effect outside the cash report. The rule for auto-detecting "Cash" (liquid assets) from account names has changed in this release - see [Account types]. This is to simplify how account types are detected and configured. If you use the cashflow report without explicitly declaring accounts as Cash, you might notice a change, and might need to add explicit account type: tags.
This commit is contained in:
		
							parent
							
								
									2e4cfccf1b
								
							
						
					
					
						commit
						31fdcdb8ef
					
				| @ -96,7 +96,7 @@ accountSummarisedName a | |||||||
| -- | Regular expressions matching common English top-level account names, | -- | Regular expressions matching common English top-level account names, | ||||||
| -- used as a fallback when account types are not declared. | -- used as a fallback when account types are not declared. | ||||||
| assetAccountRegex      = toRegexCI' "^assets?(:|$)" | assetAccountRegex      = toRegexCI' "^assets?(:|$)" | ||||||
| cashAccountRegex       = toRegexCI' "(investment|receivable|:A/R|:fixed)" | cashAccountRegex       = toRegexCI' "^assets?(:.+)?:(cash|bank|che(ck|que?)(ing)?|savings?|current)(:|$)" | ||||||
| liabilityAccountRegex  = toRegexCI' "^(debts?|liabilit(y|ies))(:|$)" | liabilityAccountRegex  = toRegexCI' "^(debts?|liabilit(y|ies))(:|$)" | ||||||
| equityAccountRegex     = toRegexCI' "^equity(:|$)" | equityAccountRegex     = toRegexCI' "^equity(:|$)" | ||||||
| conversionAccountRegex = toRegexCI' "^equity:(trad(e|ing)|conversion)s?(:|$)" | conversionAccountRegex = toRegexCI' "^equity:(trad(e|ing)|conversion)s?(:|$)" | ||||||
| @ -107,8 +107,8 @@ expenseAccountRegex    = toRegexCI' "^expenses?(:|$)" | |||||||
| -- matching common English top-level account names. | -- matching common English top-level account names. | ||||||
| accountNameInferType :: AccountName -> Maybe AccountType | accountNameInferType :: AccountName -> Maybe AccountType | ||||||
| accountNameInferType a | accountNameInferType a | ||||||
|   | a == "asset" || a == "assets"           = Just Asset |   | regexMatchText cashAccountRegex       a = Just Cash | ||||||
|   | regexMatchText assetAccountRegex      a = Just $ if regexMatchText cashAccountRegex a then Asset else Cash |   | regexMatchText assetAccountRegex      a = Just Asset | ||||||
|   | regexMatchText liabilityAccountRegex  a = Just Liability |   | regexMatchText liabilityAccountRegex  a = Just Liability | ||||||
|   | regexMatchText conversionAccountRegex a = Just Conversion |   | regexMatchText conversionAccountRegex a = Just Conversion | ||||||
|   | regexMatchText equityAccountRegex     a = Just Equity |   | regexMatchText equityAccountRegex     a = Just Equity | ||||||
|  | |||||||
| @ -466,41 +466,27 @@ journalAccountTypeQuery atypes fallbackregex Journal{jdeclaredaccounttypes} = | |||||||
| -- or otherwise for accounts with names matched by the case-insensitive  | -- or otherwise for accounts with names matched by the case-insensitive  | ||||||
| -- regular expression @^assets?(:|$)@. | -- regular expression @^assets?(:|$)@. | ||||||
| journalAssetAccountQuery :: Journal -> Query | journalAssetAccountQuery :: Journal -> Query | ||||||
| journalAssetAccountQuery j =  | journalAssetAccountQuery j = | ||||||
|   Or [ |   Or [ | ||||||
|      journalAccountTypeQuery [Asset] assetAccountRegex j |      journalAccountTypeQuery [Asset] assetAccountRegex j | ||||||
|     ,journalCashAccountOnlyQuery j |     ,journalCashAccountOnlyQuery j | ||||||
|   ] |   ] | ||||||
| 
 | 
 | ||||||
| -- | A query for accounts in this journal which have been |  | ||||||
| -- declared as Asset (and not Cash) by account directives,  |  | ||||||
| -- or otherwise for accounts with names matched by the case-insensitive  |  | ||||||
| -- regular expression @^assets?(:|$)@. |  | ||||||
| journalAssetNonCashAccountQuery :: Journal -> Query |  | ||||||
| journalAssetNonCashAccountQuery = journalAccountTypeQuery [Asset] assetAccountRegex |  | ||||||
| 
 |  | ||||||
| -- | A query for Cash (liquid asset) accounts in this journal, ie accounts | -- | A query for Cash (liquid asset) accounts in this journal, ie accounts | ||||||
| -- declared as Cash by account directives, or otherwise Asset accounts whose  | -- declared as Cash by account directives, or otherwise accounts whose | ||||||
| -- names do not include the case-insensitive regular expression  | -- names match the case-insensitive regular expression | ||||||
| -- @(investment|receivable|:A/R|:fixed)@. | -- @(^assets:(.+:)?(cash|bank)(:|$)@. | ||||||
| journalCashAccountQuery  :: Journal -> Query | journalCashAccountQuery :: Journal -> Query | ||||||
| journalCashAccountQuery j = | journalCashAccountQuery = journalAccountTypeQuery [Cash] cashAccountRegex | ||||||
|   case M.lookup Cash (jdeclaredaccounttypes j) of |  | ||||||
|     Just _  -> journalCashAccountOnlyQuery j |  | ||||||
|     Nothing -> |  | ||||||
|       -- no Cash accounts are declared; query for Asset accounts and exclude some of them |  | ||||||
|       And [ journalAssetNonCashAccountQuery j, Not $ Acct cashAccountRegex ] |  | ||||||
| 
 | 
 | ||||||
| -- | A query for accounts in this journal specifically declared as Cash by  | -- | A query for accounts in this journal specifically declared as Cash by  | ||||||
| -- account directives, or otherwise the None query. | -- account directives, or otherwise the None query. | ||||||
| journalCashAccountOnlyQuery  :: Journal -> Query | journalCashAccountOnlyQuery :: Journal -> Query | ||||||
| journalCashAccountOnlyQuery j =  | journalCashAccountOnlyQuery j | ||||||
|   case M.lookup Cash (jdeclaredaccounttypes j) of |   -- Cash accounts are declared; get a query for them (the fallback regex won't be used) | ||||||
|     Just _  ->  |   | Cash `M.member` jdeclaredaccounttypes j = journalAccountTypeQuery [Cash] notused j | ||||||
|       -- Cash accounts are declared; get a query for them (the fallback regex won't be used) |   | otherwise = None | ||||||
|       journalAccountTypeQuery [Cash] notused j |   where notused = error' "journalCashAccountOnlyQuery: this should not have happened!"  -- PARTIAL: | ||||||
|         where notused = error' "journalCashAccountOnlyQuery: this should not have happened!"  -- PARTIAL: |  | ||||||
|     Nothing -> None |  | ||||||
| 
 | 
 | ||||||
| -- | A query for accounts in this journal which have been | -- | A query for accounts in this journal which have been | ||||||
| -- declared as Liability by account directives, or otherwise for | -- declared as Liability by account directives, or otherwise for | ||||||
| @ -1319,7 +1305,7 @@ tests_Journal = testGroup "Journal" [ | |||||||
|       namesfrom qfunc = journalAccountNamesMatching (qfunc j) j |       namesfrom qfunc = journalAccountNamesMatching (qfunc j) j | ||||||
|     in [testCase "assets"      $ assertEqual "" ["assets","assets:bank","assets:bank:checking","assets:bank:saving","assets:cash"] |     in [testCase "assets"      $ assertEqual "" ["assets","assets:bank","assets:bank:checking","assets:bank:saving","assets:cash"] | ||||||
|          (namesfrom journalAssetAccountQuery) |          (namesfrom journalAssetAccountQuery) | ||||||
|        ,testCase "cash"        $ assertEqual "" ["assets","assets:bank","assets:bank:checking","assets:bank:saving","assets:cash"] |        ,testCase "cash"        $ assertEqual "" ["assets:bank","assets:bank:checking","assets:bank:saving","assets:cash"] | ||||||
|          (namesfrom journalCashAccountQuery) |          (namesfrom journalCashAccountQuery) | ||||||
|        ,testCase "liabilities" $ assertEqual "" ["liabilities","liabilities:debts"] |        ,testCase "liabilities" $ assertEqual "" ["liabilities","liabilities:debts"] | ||||||
|          (namesfrom journalLiabilityAccountQuery) |          (namesfrom journalLiabilityAccountQuery) | ||||||
|  | |||||||
| @ -1,150 +1,86 @@ | |||||||
| # 1. | # 1. | ||||||
| hledger -f - cashflow | < | ||||||
| <<< |  | ||||||
| 2016/1/1 | 2016/1/1 | ||||||
|   assets  1 |   assets:cash  1 | ||||||
|   b |   b | ||||||
| >>> | $ hledger -f - cashflow | ||||||
| Cashflow Statement 2016-01-01 | Cashflow Statement 2016-01-01 | ||||||
| 
 | 
 | ||||||
|             || 2016-01-01  |              || 2016-01-01  | ||||||
| ============++============ | =============++============ | ||||||
|  Cash flows ||             |  Cash flows  ||             | ||||||
| ------------++------------ | -------------++------------ | ||||||
|  assets     ||          1  |  assets:cash ||          1  | ||||||
| ------------++------------ | -------------++------------ | ||||||
|             ||          1  |              ||          1  | ||||||
| >>>2 | >2 | ||||||
| >>>= 0 | >= 0 | ||||||
|  | 
 | ||||||
|  | < | ||||||
|  | 2015/10/10 Client A | Invoice #1 | ||||||
|  |     assets:receivables      $10,000.00 | ||||||
|  |     revenue:clients:A      -$10,000.00 | ||||||
|  | 
 | ||||||
|  | 2015/11/02 Deposit | Invoice #1 | ||||||
|  |     assets:bank:checking    $10,000.00 | ||||||
|  |     assets:receivables     -$10,000.00 | ||||||
|  | 
 | ||||||
|  | 2016/02/01 Client B | Invoice #2 | ||||||
|  |     assets:receivables          $10.00 | ||||||
|  |     revenue:clients:B          -$10.00 | ||||||
|  | 
 | ||||||
|  | 2016/02/15 ACME | Hosting Costs | ||||||
|  |     expense:hosting             $50.00 | ||||||
|  |     assets:bank:checking       -$50.00 | ||||||
|  | 
 | ||||||
|  | 2016/03/01 Deposit | Invoice #2 | ||||||
|  |     assets:bank:checking        $10.00 | ||||||
|  |     assets:receivables         -$10.00 | ||||||
| 
 | 
 | ||||||
| # 2. Period reporting works for a specific year | # 2. Period reporting works for a specific year | ||||||
| hledger -f - cashflow -b 2016 -e 2017 | $ hledger -f - cashflow -b 2016 -e 2017 | ||||||
| <<< |  | ||||||
| 2015/10/10 Client A | Invoice #1 |  | ||||||
|     assets:receivables      $10,000.00 |  | ||||||
|     revenue:clients:A      -$10,000.00 |  | ||||||
| 
 |  | ||||||
| 2015/11/02 Deposit | Invoice #1 |  | ||||||
|     assets:checking         $10,000.00 |  | ||||||
|     assets:receivables     -$10,000.00 |  | ||||||
| 
 |  | ||||||
| 2016/02/01 Client B | Invoice #2 |  | ||||||
|     assets:receivables          $10.00 |  | ||||||
|     revenue:clients:B          -$10.00 |  | ||||||
| 
 |  | ||||||
| 2016/02/15 ACME | Hosting Costs |  | ||||||
|     expense:hosting             $50.00 |  | ||||||
|     assets:checking            -$50.00 |  | ||||||
| 
 |  | ||||||
| 2016/03/01 Deposit | Invoice #2 |  | ||||||
|     assets:checking             $10.00 |  | ||||||
|     assets:receivables         -$10.00 |  | ||||||
| >>> |  | ||||||
| Cashflow Statement 2016 | Cashflow Statement 2016 | ||||||
| 
 | 
 | ||||||
|                  ||    2016  |                       ||    2016  | ||||||
| =================++========= | ======================++========= | ||||||
|  Cash flows      ||          |  Cash flows           ||          | ||||||
| -----------------++--------- | ----------------------++--------- | ||||||
|  assets:checking || $-40.00  |  assets:bank:checking || $-40.00  | ||||||
| -----------------++--------- | ----------------------++--------- | ||||||
|                  || $-40.00  |                       || $-40.00  | ||||||
| >>>2 | >2 | ||||||
| >>>= 0 | >= 0 | ||||||
| 
 | 
 | ||||||
| # 3. Period reporting works for two years | # 3. Period reporting works for two years | ||||||
| hledger -f - cashflow -b 2015 -e 2017 | $ hledger -f - cashflow -b 2015 -e 2017 | ||||||
| <<< |  | ||||||
| 2015/10/10 Client A | Invoice #1 |  | ||||||
|     assets:receivables      $10,000.00 |  | ||||||
|     revenue:clients:A      -$10,000.00 |  | ||||||
| 
 |  | ||||||
| 2015/11/02 Deposit | Invoice #1 |  | ||||||
|     assets:checking         $10,000.00 |  | ||||||
|     assets:receivables     -$10,000.00 |  | ||||||
| 
 |  | ||||||
| 2016/02/01 Client B | Invoice #2 |  | ||||||
|     assets:receivables          $10.00 |  | ||||||
|     revenue:clients:B          -$10.00 |  | ||||||
| 
 |  | ||||||
| 2016/02/15 ACME | Hosting Costs |  | ||||||
|     expense:hosting             $50.00 |  | ||||||
|     assets:checking            -$50.00 |  | ||||||
| 
 |  | ||||||
| 2016/03/01 Deposit | Invoice #2 |  | ||||||
|     assets:checking             $10.00 |  | ||||||
|     assets:receivables         -$10.00 |  | ||||||
| >>> |  | ||||||
| Cashflow Statement 2015-01-01..2016-12-31 | Cashflow Statement 2015-01-01..2016-12-31 | ||||||
| 
 | 
 | ||||||
|                  || 2015-01-01..2016-12-31  |                       || 2015-01-01..2016-12-31  | ||||||
| =================++======================== | ======================++======================== | ||||||
|  Cash flows      ||                         |  Cash flows           ||                         | ||||||
| -----------------++------------------------ | ----------------------++------------------------ | ||||||
|  assets:checking ||              $9,960.00  |  assets:bank:checking ||              $9,960.00  | ||||||
| -----------------++------------------------ | ----------------------++------------------------ | ||||||
|                  ||              $9,960.00  |                       ||              $9,960.00  | ||||||
| >>>2 | >2 | ||||||
| >>>= 0 | >= 0 | ||||||
| 
 | 
 | ||||||
| # 4. Period reporting works for one month | # 4. Period reporting works for one month | ||||||
| hledger -f - cashflow -b 2015/11 -e 2015/12 | $ hledger -f - cashflow -b 2015/11 -e 2015/12 | ||||||
| <<< |  | ||||||
| 2015/10/10 Client A | Invoice #1 |  | ||||||
|     assets:receivables      $10,000.00 |  | ||||||
|     revenue:clients:A      -$10,000.00 |  | ||||||
| 
 |  | ||||||
| 2015/11/02 Deposit | Invoice #1 |  | ||||||
|     assets:checking         $10,000.00 |  | ||||||
|     assets:receivables     -$10,000.00 |  | ||||||
| 
 |  | ||||||
| 2016/02/01 Client B | Invoice #2 |  | ||||||
|     assets:receivables          $10.00 |  | ||||||
|     revenue:clients:B          -$10.00 |  | ||||||
| 
 |  | ||||||
| 2016/02/15 ACME | Hosting Costs |  | ||||||
|     expense:hosting             $50.00 |  | ||||||
|     assets:checking            -$50.00 |  | ||||||
| 
 |  | ||||||
| 2016/03/01 Deposit | Invoice #2 |  | ||||||
|     assets:checking             $10.00 |  | ||||||
|     assets:receivables         -$10.00 |  | ||||||
| >>> |  | ||||||
| Cashflow Statement 2015-11 | Cashflow Statement 2015-11 | ||||||
| 
 | 
 | ||||||
|                  ||        Nov  |                       ||        Nov  | ||||||
| =================++============ | ======================++============ | ||||||
|  Cash flows      ||             |  Cash flows           ||             | ||||||
| -----------------++------------ | ----------------------++------------ | ||||||
|  assets:checking || $10,000.00  |  assets:bank:checking || $10,000.00  | ||||||
| -----------------++------------ | ----------------------++------------ | ||||||
|                  || $10,000.00  |                       || $10,000.00  | ||||||
| >>>2 | >2 | ||||||
| >>>= 0 | >= 0 | ||||||
| 
 | 
 | ||||||
| # 5. Period reporting works for one month in another year | # 5. Period reporting works for one month in another year | ||||||
| hledger -f - cashflow -b 2016/10 -e 2016/11 | $ hledger -f - cashflow -b 2016/10 -e 2016/11 | ||||||
| <<< |  | ||||||
| 2015/10/10 Client A | Invoice #1 |  | ||||||
|     assets:receivables      $10,000.00 |  | ||||||
|     revenue:clients:A      -$10,000.00 |  | ||||||
| 
 |  | ||||||
| 2015/11/02 Deposit | Invoice #1 |  | ||||||
|     assets:checking         $10,000.00 |  | ||||||
|     assets:receivables     -$10,000.00 |  | ||||||
| 
 |  | ||||||
| 2016/02/01 Client B | Invoice #2 |  | ||||||
|     assets:receivables          $10.00 |  | ||||||
|     revenue:clients:B          -$10.00 |  | ||||||
| 
 |  | ||||||
| 2016/02/15 ACME | Hosting Costs |  | ||||||
|     expense:hosting             $50.00 |  | ||||||
|     assets:checking            -$50.00 |  | ||||||
| 
 |  | ||||||
| 2016/03/01 Deposit | Invoice #2 |  | ||||||
|     assets:checking             $10.00 |  | ||||||
|     assets:receivables         -$10.00 |  | ||||||
| >>> |  | ||||||
| Cashflow Statement 2016-10 | Cashflow Statement 2016-10 | ||||||
| 
 | 
 | ||||||
|             || Oct  |             || Oct  | ||||||
| @ -153,12 +89,11 @@ Cashflow Statement 2016-10 | |||||||
| ------------++----- | ------------++----- | ||||||
| ------------++----- | ------------++----- | ||||||
|             ||      |             ||      | ||||||
| >>>2 | >2 | ||||||
| >>>= 0 | >= 0 | ||||||
| 
 | 
 | ||||||
| # 6. Multicolumn test | # 6. Multicolumn test | ||||||
| hledger -f sample.journal cashflow -p 'monthly in 2008' | $ hledger -f sample.journal cashflow -p 'monthly in 2008' | ||||||
| >>> |  | ||||||
| Cashflow Statement 2008 | Cashflow Statement 2008 | ||||||
| 
 | 
 | ||||||
|                       || Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec  |                       || Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec  | ||||||
| @ -170,11 +105,10 @@ Cashflow Statement 2008 | |||||||
|  assets:cash          ||   0    0    0    0    0  $-2    0    0    0    0    0    0  |  assets:cash          ||   0    0    0    0    0  $-2    0    0    0    0    0    0  | ||||||
| ----------------------++------------------------------------------------------------ | ----------------------++------------------------------------------------------------ | ||||||
|                       ||  $1    0    0    0    0  $-1    0    0    0    0    0  $-1  |                       ||  $1    0    0    0    0  $-1    0    0    0    0    0  $-1  | ||||||
| >>>= 0 | >= 0 | ||||||
| 
 | 
 | ||||||
| # 7. Multicolumn test (historical) | # 7. Multicolumn test (historical) | ||||||
| hledger -f sample.journal cashflow -p 'monthly in 2008' -A --historical | $ hledger -f sample.journal cashflow -p 'monthly in 2008' -A --historical | ||||||
| >>> |  | ||||||
| Cashflow Statement 2008-01-31..2008-12-31 (Historical Ending Balances) | Cashflow Statement 2008-01-31..2008-12-31 (Historical Ending Balances) | ||||||
| 
 | 
 | ||||||
|                       || 2008-01-31  2008-02-29  2008-03-31  2008-04-30  2008-05-31  2008-06-30  2008-07-31  2008-08-31  2008-09-30  2008-10-31  2008-11-30  2008-12-31  Average  |                       || 2008-01-31  2008-02-29  2008-03-31  2008-04-30  2008-05-31  2008-06-30  2008-07-31  2008-08-31  2008-09-30  2008-10-31  2008-11-30  2008-12-31  Average  | ||||||
| @ -186,11 +120,10 @@ Cashflow Statement 2008-01-31..2008-12-31 (Historical Ending Balances) | |||||||
|  assets:cash          ||          0           0           0           0           0         $-2         $-2         $-2         $-2         $-2         $-2         $-2      $-1  |  assets:cash          ||          0           0           0           0           0         $-2         $-2         $-2         $-2         $-2         $-2         $-2      $-1  | ||||||
| ----------------------++--------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------++--------------------------------------------------------------------------------------------------------------------------------------------------------- | ||||||
|                       ||         $1          $1          $1          $1          $1           0           0           0           0           0           0         $-1        0  |                       ||         $1          $1          $1          $1          $1           0           0           0           0           0           0         $-1        0  | ||||||
| >>>= 0 | >= 0 | ||||||
| 
 | 
 | ||||||
| # 8. without -N/--no-total | # 8. without -N/--no-total | ||||||
| hledger -f sample.journal cf  | $ hledger -f sample.journal cf  | ||||||
| >>> |  | ||||||
| Cashflow Statement 2008 | Cashflow Statement 2008 | ||||||
| 
 | 
 | ||||||
|                     || 2008  |                     || 2008  | ||||||
| @ -201,12 +134,11 @@ Cashflow Statement 2008 | |||||||
|  assets:cash        ||  $-2  |  assets:cash        ||  $-2  | ||||||
| --------------------++------ | --------------------++------ | ||||||
|                     ||  $-1  |                     ||  $-1  | ||||||
| >>>2 | >2 | ||||||
| >>>= 0 | >= 0 | ||||||
| 
 | 
 | ||||||
| # 9. with -N | # 9. with -N | ||||||
| hledger -f sample.journal cf -N | $ hledger -f sample.journal cf -N | ||||||
| >>> |  | ||||||
| Cashflow Statement 2008 | Cashflow Statement 2008 | ||||||
| 
 | 
 | ||||||
|                     || 2008  |                     || 2008  | ||||||
| @ -215,28 +147,27 @@ Cashflow Statement 2008 | |||||||
| --------------------++------ | --------------------++------ | ||||||
|  assets:bank:saving ||   $1  |  assets:bank:saving ||   $1  | ||||||
|  assets:cash        ||  $-2  |  assets:cash        ||  $-2  | ||||||
| >>>2 | >2 | ||||||
| >>>= 0 | >= 0 | ||||||
| 
 | 
 | ||||||
| # 10. exclude fixed assets from cashflow | # 10. exclude fixed assets from cashflow | ||||||
| hledger -f - cashflow | < | ||||||
| <<< |  | ||||||
| 2016/1/1 | 2016/1/1 | ||||||
|   assets  1 |   assets:cash  1 | ||||||
|   b |   b | ||||||
| 
 | 
 | ||||||
| 2016/1/1 | 2016/1/1 | ||||||
|   assets:fixed assets:equipment  1 |   assets:fixed assets:equipment  1 | ||||||
|   b |   b | ||||||
| >>> | $ hledger -f - cashflow | ||||||
| Cashflow Statement 2016-01-01 | Cashflow Statement 2016-01-01 | ||||||
| 
 | 
 | ||||||
|             || 2016-01-01  |              || 2016-01-01  | ||||||
| ============++============ | =============++============ | ||||||
|  Cash flows ||             |  Cash flows  ||             | ||||||
| ------------++------------ | -------------++------------ | ||||||
|  assets     ||          1  |  assets:cash ||          1  | ||||||
| ------------++------------ | -------------++------------ | ||||||
|             ||          1  |              ||          1  | ||||||
| >>>2 | >2 | ||||||
| >>>= 0 | >= 0 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user