journal: also support the total lot price variants ({{}}, {{=}})
This commit is contained in:
		
							parent
							
								
									5beeb56a87
								
							
						
					
					
						commit
						fedde7fab1
					
				| @ -767,11 +767,13 @@ balanceassertionp = do | ||||
| lotpricep :: JournalParser m (Either Amount Amount) | ||||
| lotpricep = (do | ||||
|   char '{' | ||||
|   doublebrace <- option False $ char '{' >> pure True | ||||
|   fixed <- fmap isJust $ optional $ lift (skipMany spacenonewline) >> char '=' | ||||
|   lift (skipMany spacenonewline) | ||||
|   a <- amountwithoutpricep | ||||
|   lift (skipMany spacenonewline) | ||||
|   char '}' | ||||
|   when (doublebrace) $ void $ char '}' | ||||
|   return $ (if fixed then Left else Right) a | ||||
|   ) <?> "ledger-style lot price or fixed lot price" | ||||
| 
 | ||||
|  | ||||
| @ -855,6 +855,10 @@ tests_JournalReader = tests "JournalReader" [ | ||||
| 
 | ||||
|     ,test "quoted commodity symbol with digits" $ assertParse (postingp Nothing) "  a  1 \"DE123\"\n" | ||||
| 
 | ||||
|     ,test "only lot price" $ assertParse (postingp Nothing) "  a  1A {1B}\n" | ||||
|     ,test "fixed lot price" $ assertParse (postingp Nothing) "  a  1A {=1B}\n" | ||||
|     ,test "total lot price" $ assertParse (postingp Nothing) "  a  1A {{1B}}\n" | ||||
|     ,test "fixed total lot price, and spaces" $ assertParse (postingp Nothing) "  a  1A {{  =  1B }}\n" | ||||
|     ,test "lot price before transaction price" $ assertParse (postingp Nothing) "  a  1A {1B} @ 1B\n" | ||||
|     ,test "lot price after transaction price" $ assertParse (postingp Nothing) "  a  1A @ 1B {1B}\n" | ||||
|     ,test "lot price after balance assertion not allowed" $ assertParseError (postingp Nothing) "  a  1A @ 1B = 1A {1B}\n" "unexpected '{'" | ||||
|  | ||||
| @ -6,7 +6,8 @@ User-visible changes in the hledger command line tool and library. | ||||
| - Improved parse compatibility for Ledger lot prices: | ||||
|   hledger up to 1.17.1 did not accept Ledger's lot price syntax except | ||||
|   in vary limited circumstances (`{= }` at the end of the posting line). | ||||
|   hledger now accepts all three lot price syntaxes (`{ }`, `{{ }}`, `{= }`), | ||||
|   hledger now accepts all four of Ledger's lot price syntaxes  | ||||
|   (`{PRICE}`, `{{PRICE}}`, `{=PRICE}`, `{{=PRICE}}`), | ||||
|   anywhere after the posting amount but before any balance assertion. | ||||
|   All of these lot prices are ignored. | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user