parsing: make balance assertions more robust with different precisions (#119)

Also note another issue.
This commit is contained in:
Simon Michael 2013-06-01 13:39:00 -07:00
parent 44545d6ec7
commit c2fa4b3c21
3 changed files with 46 additions and 1 deletions

View File

@ -81,6 +81,7 @@ module Hledger.Data.Amount (
divideMixedAmount,
isNegativeMixedAmount,
isZeroMixedAmount,
isReallyZeroMixedAmount,
isReallyZeroMixedAmountCost,
-- ** rendering
showMixedAmount,

View File

@ -391,7 +391,9 @@ checkBalanceAssertion :: ([String],MixedAmount) -> [Posting] -> ([String],MixedA
checkBalanceAssertion (errs,bal) ps
| null ps = (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')
where
p = last ps

View File

@ -69,3 +69,45 @@ hledgerdev -f - stats
>>> /Transactions/
>>>2
>>>=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