diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index 546b0ab7f..af3947693 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -81,6 +81,7 @@ module Hledger.Data.Amount ( divideMixedAmount, isNegativeMixedAmount, isZeroMixedAmount, + isReallyZeroMixedAmount, isReallyZeroMixedAmountCost, -- ** rendering showMixedAmount, diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index d02a34123..b35b9196f 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -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 diff --git a/tests/balance-assertions.test b/tests/balance-assertions.test index 1859a4f5f..d98cd82ea 100755 --- a/tests/balance-assertions.test +++ b/tests/balance-assertions.test @@ -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