parsing: make balance assertions more robust with different precisions (#119)
Also note another issue.
This commit is contained in:
		
							parent
							
								
									44545d6ec7
								
							
						
					
					
						commit
						c2fa4b3c21
					
				| @ -81,6 +81,7 @@ module Hledger.Data.Amount ( | |||||||
|   divideMixedAmount, |   divideMixedAmount, | ||||||
|   isNegativeMixedAmount, |   isNegativeMixedAmount, | ||||||
|   isZeroMixedAmount, |   isZeroMixedAmount, | ||||||
|  |   isReallyZeroMixedAmount, | ||||||
|   isReallyZeroMixedAmountCost, |   isReallyZeroMixedAmountCost, | ||||||
|   -- ** rendering |   -- ** rendering | ||||||
|   showMixedAmount, |   showMixedAmount, | ||||||
|  | |||||||
| @ -391,7 +391,9 @@ checkBalanceAssertion :: ([String],MixedAmount) -> [Posting] -> ([String],MixedA | |||||||
| checkBalanceAssertion (errs,bal) ps | checkBalanceAssertion (errs,bal) ps | ||||||
|   | null ps = (errs,bal) |   | null ps = (errs,bal) | ||||||
|   | isNothing assertion = (errs,bal) |   | isNothing assertion = (errs,bal) | ||||||
|   | bal' /= assertedbal = (errs++[err], bal') |   -- | bal' /= assertedbal  -- MixedAmount's Eq instance currently gets confused by different precisions | ||||||
|  |   | not $ isReallyZeroMixedAmount (bal' - assertedbal) | ||||||
|  |       = (errs++[err], bal') | ||||||
|   | otherwise = (errs,bal') |   | otherwise = (errs,bal') | ||||||
|   where |   where | ||||||
|     p = last ps |     p = last ps | ||||||
|  | |||||||
| @ -69,3 +69,45 @@ hledgerdev -f - stats | |||||||
| >>> /Transactions/ | >>> /Transactions/ | ||||||
| >>>2 | >>>2 | ||||||
| >>>=0 | >>>=0 | ||||||
|  | 
 | ||||||
|  | # 5. should work for fractional amount with trailing zeros | ||||||
|  | hledgerdev -f - stats | ||||||
|  | <<< | ||||||
|  | 2013/1/1 | ||||||
|  |   a    $1.20  =$1.20 | ||||||
|  |   b           =-$1.20 | ||||||
|  | 
 | ||||||
|  | 2013/1/2 | ||||||
|  |   a    $0.10  =$1.3 | ||||||
|  |   b           =-$1.3 | ||||||
|  | 
 | ||||||
|  | 2013/1/3 | ||||||
|  |   a    $0.7   =$2 | ||||||
|  |   b           =-$2 | ||||||
|  | 
 | ||||||
|  | >>> /Transactions/ | ||||||
|  | >>>2 | ||||||
|  | >>>=0 | ||||||
|  | 
 | ||||||
|  | # 6. what should happen here ? Currently, | ||||||
|  | # in a, 3.4 EUR @@ $5.6 and -3.4 EUR cancel out (wrong ?) | ||||||
|  | # in b,  | ||||||
|  | #  | ||||||
|  | # hledgerdev -f - stats | ||||||
|  | # <<< | ||||||
|  | # 2013/1/1 | ||||||
|  | #   a    $1.20 | ||||||
|  | #   a    3.4 EUR @@ $5.6 | ||||||
|  | #   b   | ||||||
|  | 
 | ||||||
|  | # 2013/1/2 | ||||||
|  | #   a    -3.4 EUR | ||||||
|  | #   b | ||||||
|  | 
 | ||||||
|  | # 2013/1/3 | ||||||
|  | #   a    $0.1   =$1.30 | ||||||
|  | #   b           =-$1.30 | ||||||
|  | 
 | ||||||
|  | # >>> /Transactions/ | ||||||
|  | # >>>2 | ||||||
|  | # >>>=0 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user