diff --git a/odoo/addons/base/models/res_currency.py b/odoo/addons/base/models/res_currency.py index e3624000a0e..c75ddfe0021 100644 --- a/odoo/addons/base/models/res_currency.py +++ b/odoo/addons/base/models/res_currency.py @@ -134,11 +134,7 @@ class Currency(models.Model): :param float amount: the amount to round :return: rounded float """ - # TODO: Need to check why it calls round() from sale.py, _amount_all() with *No* ID after below commits, - # https://github.com/odoo/odoo/commit/36ee1ad813204dcb91e9f5f20d746dff6f080ac2 - # https://github.com/odoo/odoo/commit/0b6058c585d7d9a57bd7581b8211f20fca3ec3f7 - # Removing self.ensure_one() will make few test cases to break of modules event_sale, sale_mrp and stock_dropshipping. - #self.ensure_one() + self.ensure_one() return tools.float_round(amount, precision_rounding=self.rounding) @api.multi @@ -162,6 +158,7 @@ class Currency(models.Model): With the new API, call it like: ``currency.compare_amounts(amount1, amount2)``. """ + self.ensure_one() return tools.float_compare(amount1, amount2, precision_rounding=self.rounding) @api.multi @@ -177,6 +174,7 @@ class Currency(models.Model): With the new API, call it like: ``currency.is_zero(amount)``. """ + self.ensure_one() return tools.float_is_zero(amount, precision_rounding=self.rounding) @api.model diff --git a/odoo/addons/base/tests/test_float.py b/odoo/addons/base/tests/test_float.py index 4447b9de1c0..4dbf1f5f139 100644 --- a/odoo/addons/base/tests/test_float.py +++ b/odoo/addons/base/tests/test_float.py @@ -201,12 +201,30 @@ class TestFloatPrecision(TransactionCase): with self.assertRaises(AssertionError): float_is_zero(0.01, precision_digits=3, precision_rounding=0.01) + with self.assertRaises(AssertionError): + float_is_zero(0.0, precision_rounding=0.0) + + with self.assertRaises(AssertionError): + float_is_zero(0.0, precision_rounding=-0.1) + with self.assertRaises(AssertionError): float_compare(0.01, 0.02, precision_digits=3, precision_rounding=0.01) + with self.assertRaises(AssertionError): + float_compare(1.0, 1.0, precision_rounding=0.0) + + with self.assertRaises(AssertionError): + float_compare(1.0, 1.0, precision_rounding=-0.1) + with self.assertRaises(AssertionError): float_round(0.01, precision_digits=3, precision_rounding=0.01) + with self.assertRaises(AssertionError): + float_round(1.25, precision_rounding=0.0) + + with self.assertRaises(AssertionError): + float_round(1.25, precision_rounding=-0.1) + def test_amount_to_text_10(self): """ verify that amount_to_text works as expected """ currency = self.env.ref('base.EUR') diff --git a/odoo/tools/float_utils.py b/odoo/tools/float_utils.py index 12881503f32..47b5d72c069 100644 --- a/odoo/tools/float_utils.py +++ b/odoo/tools/float_utils.py @@ -26,6 +26,8 @@ def _float_check_precision(precision_digits=None, precision_rounding=None): assert (precision_digits is not None or precision_rounding is not None) and \ not (precision_digits and precision_rounding),\ "exactly one of precision_digits and precision_rounding must be specified" + assert precision_rounding is None or precision_rounding > 0,\ + "precision_rounding must be positive, got %s" % precision_rounding if precision_digits is not None: return 10 ** -precision_digits return precision_rounding @@ -51,7 +53,8 @@ def float_round(value, precision_digits=None, precision_rounding=None, rounding_ """ rounding_factor = _float_check_precision(precision_digits=precision_digits, precision_rounding=precision_rounding) - if rounding_factor == 0 or value == 0: return 0.0 + if rounding_factor == 0 or value == 0: + return 0.0 # NORMALIZE - ROUND - DENORMALIZE # In order to easily support rounding to arbitrary 'steps' (e.g. coin values),