mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-25 19:31:44 +03:00
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,
|
||||
isNegativeMixedAmount,
|
||||
isZeroMixedAmount,
|
||||
isReallyZeroMixedAmount,
|
||||
isReallyZeroMixedAmountCost,
|
||||
-- ** rendering
|
||||
showMixedAmount,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user