csv: accept a balance field assignment instead of an amount (#1000)
This commit is contained in:
		
							parent
							
								
									72377a54c4
								
							
						
					
					
						commit
						61e8ccbf88
					
				| @ -452,13 +452,19 @@ validateRules :: CsvRules -> ExceptT String IO CsvRules | |||||||
| validateRules rules = do | validateRules rules = do | ||||||
|   unless (isAssigned "date")   $ ExceptT $ return $ Left "Please specify (at top level) the date field. Eg: date %1\n" |   unless (isAssigned "date")   $ ExceptT $ return $ Left "Please specify (at top level) the date field. Eg: date %1\n" | ||||||
|   unless ((amount && not (amountin || amountout)) || |   unless ((amount && not (amountin || amountout)) || | ||||||
|           (not amount && (amountin && amountout))) |           (not amount && (amountin && amountout)) || | ||||||
|     $ ExceptT $ return $ Left "Please specify (at top level) either the amount field, or both the amount-in and amount-out fields. Eg: amount %2\n" |           balance) | ||||||
|  |     $ ExceptT $ return $ Left $ unlines [ | ||||||
|  |        "Please specify (as a top level CSV rule) either the amount field," | ||||||
|  |       ,"both the amount-in and amount-out fields, or the balance field. Eg:" | ||||||
|  |       ,"amount %2\n" | ||||||
|  |       ] | ||||||
|   ExceptT $ return $ Right rules |   ExceptT $ return $ Right rules | ||||||
|   where |   where | ||||||
|     amount = isAssigned "amount" |     amount    = isAssigned "amount" | ||||||
|     amountin = isAssigned "amount-in" |     amountin  = isAssigned "amount-in" | ||||||
|     amountout = isAssigned "amount-out" |     amountout = isAssigned "amount-out" | ||||||
|  |     balance   = isAssigned "balance" || isAssigned "balance1" || isAssigned "balance2" | ||||||
|     isAssigned f = isJust $ getEffectiveAssignment rules [] f |     isAssigned f = isJust $ getEffectiveAssignment rules [] f | ||||||
| 
 | 
 | ||||||
| -- parsers | -- parsers | ||||||
|  | |||||||
| @ -35,7 +35,9 @@ You can override this with the `--rules-file` option. | |||||||
| If the rules file does not exist, hledger will auto-create one with | If the rules file does not exist, hledger will auto-create one with | ||||||
| some example rules, which you'll need to adjust. | some example rules, which you'll need to adjust. | ||||||
| 
 | 
 | ||||||
| At minimum, the rules file must identify the `date` and `amount` fields.  | At minimum, the rules file must identify the date (`date`) and  | ||||||
|  | amount (`amount`, or `amount-in` and `amount-out`, or one of `balance`/`balance1`/`balance2`) | ||||||
|  | fields.  | ||||||
| It may also be necessary to specify the date format, and the number of header lines to skip. Eg: | It may also be necessary to specify the date format, and the number of header lines to skip. Eg: | ||||||
| ``` | ``` | ||||||
| fields date, _, _, amount | fields date, _, _, amount | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user