diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-02-01 18:20:28 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-02-01 18:20:28 +0100 |
| commit | e00a447e2ca277697bd3e3cae5196e8177d3e867 (patch) | |
| tree | c8580e47f101f75ceccd6ba19f9649b575f99177 /odoo/addons/base/tests/test_float.py | |
| parent | cde120058aa4edd259b7d7e1624465af313710fe (diff) | |
| parent | 7e469eb77aae1f7e05a3ce0f6575b5149fed3ca1 (diff) | |
[MERGE] forward port branch saas-11.1 up to 7e469eb77aa
Diffstat (limited to 'odoo/addons/base/tests/test_float.py')
| -rw-r--r-- | odoo/addons/base/tests/test_float.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/odoo/addons/base/tests/test_float.py b/odoo/addons/base/tests/test_float.py index 1c2fcc3e91f..6e42f8adf1d 100644 --- a/odoo/addons/base/tests/test_float.py +++ b/odoo/addons/base/tests/test_float.py @@ -92,6 +92,18 @@ class TestFloatPrecision(TransactionCase): try_round(1.8, '2', 0, method='UP') try_round(-1.8, '-2', 0, method='UP') + # Try some rounding value with rounding method DOWN instead of HALF-UP + # We use 2.425 because when normalizing 2.425 with precision_digits=3 it gives + # us 2424.9999999999995 as value, and if not handle correctly the rounding DOWN + # value will be incorrect (should be 2.425 and not 2.424) + try_round(2.425, '2.425', method='DOWN') + try_round(2.4249, '2.424', method='DOWN') + try_round(-2.425, '-2.425', method='DOWN') + try_round(-2.4249, '-2.424', method='DOWN') + try_round(-2.500, '-2.500', method='DOWN') + try_round(1.8, '1', 0, method='DOWN') + try_round(-1.8, '-1', 0, method='DOWN') + # Extended float range test, inspired by Cloves Almeida's test on bug #882036. fractions = [.0, .015, .01499, .675, .67499, .4555, .4555, .45555] expecteds = ['.00', '.02', '.01', '.68', '.67', '.46', '.456', '.4556'] @@ -135,8 +147,8 @@ class TestFloatPrecision(TransactionCase): try_compare(-657.4444, -657.445, 1) # Rounding to unusual rounding units (e.g. coin values) - def try_round(amount, expected, precision_rounding=None): - value = float_round(amount, precision_rounding=precision_rounding) + def try_round(amount, expected, precision_rounding=None, method='HALF-UP'): + value = float_round(amount, precision_rounding=precision_rounding, rounding_method=method) result = float_repr(value, precision_digits=2) self.assertEqual(result, expected, 'Rounding error: got %s, expected %s' % (result, expected)) @@ -145,6 +157,8 @@ class TestFloatPrecision(TransactionCase): try_round(457.3, '455.00', precision_rounding=5) try_round(457.5, '460.00', precision_rounding=5) try_round(457.1, '456.00', precision_rounding=3) + try_round(2.5, '2.50', precision_rounding=0.05, method='DOWN') + try_round(-2.5, '-2.50', precision_rounding=0.05, method='DOWN') def test_rounding_04(self): """ check that proper rounding is performed for float persistence """ |
