summaryrefslogtreecommitdiff
path: root/odoo/tools
diff options
context:
space:
mode:
authorJorge Pinna Puissant <jpp@odoo.com>2019-01-30 09:12:18 +0000
committerJorge Pinna Puissant <jpp@odoo.com>2019-02-13 07:05:13 +0000
commite270e9e0cc6574d2c6bdd29983d3b66d12d2ced7 (patch)
tree82e1303f90932a05086a600c1b4d38cbb2fea23c /odoo/tools
parent73fa0748da28ac475520aa390459ace55fe076c1 (diff)
[IMP] tools: float_utils, precision rounding must be positive
Adding a new rule to verify that precision_rounding is positive. Before this commit: when a precision_round was 0 or smaller than 0 the float_utils functions gave as results: * float_is_zero(0.0, precision_rounding=0.0) -> False * float_round(1.25, precision_rounding=0.0) -> 0.0 * float_compare(1.0, 1.0, precision_rounding=0.0) -> 1 These results where at least not correct at worst not logic. Now, the function raises an error when the precision_rounding is not positive
Diffstat (limited to 'odoo/tools')
-rw-r--r--odoo/tools/float_utils.py5
1 files changed, 4 insertions, 1 deletions
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),