imp: csv: Substitute empty string if csv template fails. (#1803)
This commit is contained in:
		
							parent
							
								
									9c3ee3ada4
								
							
						
					
					
						commit
						c48d98c515
					
				| @ -1249,10 +1249,10 @@ renderTemplate rules record t = maybe t mconcat $ parseMaybe | ||||
| 
 | ||||
| -- | Replace something that looks like a reference to a csv field ("%date" or "%1) | ||||
| -- with that field's value. If it doesn't look like a field reference, or if we | ||||
| -- can't find such a field, leave it unchanged. | ||||
| -- can't find such a field, replace it with the empty string. | ||||
| replaceCsvFieldReference :: CsvRules -> CsvRecord -> CsvFieldReference -> Text | ||||
| replaceCsvFieldReference rules record s = case T.uncons s of | ||||
|     Just ('%', fieldname) -> fromMaybe s $ csvFieldValue rules record fieldname | ||||
|     Just ('%', fieldname) -> fromMaybe "" $ csvFieldValue rules record fieldname | ||||
|     _                     -> s | ||||
| 
 | ||||
| -- | Get the (whitespace-stripped) value of a CSV field, identified by its name or | ||||
|  | ||||
| @ -1032,6 +1032,19 @@ $  ./csvtest.sh | ||||
| 
 | ||||
| >=0 | ||||
| 
 | ||||
| # 51. Throw an error when unable to substitute csv templates | ||||
| < | ||||
| "2021-12-23","caffe_siciliaexpenses:cibo:dolce","-10.5" | ||||
| 
 | ||||
| RULES file | ||||
| 
 | ||||
| account1 assets:bank:checking | ||||
| fields date, description, account2, amount | ||||
| 
 | ||||
| $  ./csvtest.sh | ||||
| >2 /could not balance this transaction/ | ||||
| >=1 | ||||
| 
 | ||||
| ## .  | ||||
| #< | ||||
| #$  ./csvtest.sh | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user