lib: journal: let alias/apply account affect account directives (#825)
This commit is contained in:
		
							parent
							
								
									422f1084c9
								
							
						
					
					
						commit
						6924e8390c
					
				| @ -459,7 +459,9 @@ secondarydatep primaryDate = char '=' *> datep' (Just primaryYear) | |||||||
| 
 | 
 | ||||||
| --- ** account names | --- ** account names | ||||||
| 
 | 
 | ||||||
| -- | Parse an account name, then apply any parent account prefix and/or account aliases currently in effect. | -- | Parse an account name (plus one following space if present),  | ||||||
|  | -- then apply any parent account prefix and/or account aliases currently in effect, | ||||||
|  | -- in that order. (Ie first add the parent account prefix, then rewrite with aliases). | ||||||
| modifiedaccountnamep :: JournalParser m AccountName | modifiedaccountnamep :: JournalParser m AccountName | ||||||
| modifiedaccountnamep = do | modifiedaccountnamep = do | ||||||
|   parent <- getParentAccount |   parent <- getParentAccount | ||||||
|  | |||||||
| @ -248,7 +248,7 @@ accountdirectivep :: JournalParser m () | |||||||
| accountdirectivep = do | accountdirectivep = do | ||||||
|   string "account" |   string "account" | ||||||
|   lift (skipSome spacenonewline) |   lift (skipSome spacenonewline) | ||||||
|   acct <- lift accountnamep  -- eats single spaces |   acct <- modifiedaccountnamep  -- account directives can be modified by alias/apply account | ||||||
|   macode' :: Maybe String <- (optional $ lift $ skipSome spacenonewline >> some digitChar) |   macode' :: Maybe String <- (optional $ lift $ skipSome spacenonewline >> some digitChar) | ||||||
|   let macode :: Maybe AccountCode = read <$> macode' |   let macode :: Maybe AccountCode = read <$> macode' | ||||||
|   newline |   newline | ||||||
|  | |||||||
| @ -928,6 +928,9 @@ You can clear (forget) all currently defined aliases with the `end aliases` dire | |||||||
| end aliases | end aliases | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
|  | Account aliases also affect [account directives](#declaring-accounts). | ||||||
|  | They do not affect account names being entered via hledger add or hledger-web. | ||||||
|  | 
 | ||||||
| ### Default parent account | ### Default parent account | ||||||
| 
 | 
 | ||||||
| You can specify a parent account which will be prepended to all accounts | You can specify a parent account which will be prepended to all accounts | ||||||
| @ -963,6 +966,10 @@ include personal.journal | |||||||
| 
 | 
 | ||||||
| Prior to hledger 1.0, legacy `account` and `end` spellings were also supported. | Prior to hledger 1.0, legacy `account` and `end` spellings were also supported. | ||||||
| 
 | 
 | ||||||
|  | A default parent account also affects [account directives](#declaring-accounts). | ||||||
|  | It does not affect account names being entered via hledger add or hledger-web. | ||||||
|  | If account aliases are present, they are applied after the default parent account. | ||||||
|  | 
 | ||||||
| ## Periodic transactions | ## Periodic transactions | ||||||
| 
 | 
 | ||||||
| Periodic transaction rules describe transactions that recur. | Periodic transaction rules describe transactions that recur. | ||||||
|  | |||||||
							
								
								
									
										19
									
								
								tests/journal/accounts.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								tests/journal/accounts.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | |||||||
|  | # account names | ||||||
|  | 
 | ||||||
|  | # 1. account directives are affected by aliases and apply account. | ||||||
|  | < | ||||||
|  | apply account c | ||||||
|  | alias c:a=b | ||||||
|  | account a | ||||||
|  | $ hledger -f - accounts | ||||||
|  | b | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | # TODO | ||||||
|  | # a trailing : should give a clear error | ||||||
|  | # 2009/1/1 | ||||||
|  | #  a:  1 | ||||||
|  | # $ hledger -f - print | ||||||
|  | # >2 /accountname seems ill-formed: a:/ | ||||||
|  | # >= 1 | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user