Reputation: 123
So i want to convert my code from Odoo12 to Odoo13 and i'm stuck on this part :
#digits_rounding_precision here is 0.0
digits_rounding_precision = self.currency_id.rounding
if float_is_zero(self.residual_amount, precision_rounding=digits_rounding_precision):
self.reconciled = True
else:
self.reconciled = False
I got this type of error :
precision_rounding must be positive, got %s" % precision_rounding
AssertionError: precision_rounding must be positive, got 0.0
but on Odoo12 it was fine to have 0.0 value Please help me
Upvotes: 2
Views: 1084
Reputation: 614
After looking at Odoo's source code I've found this (in Odoo 13.0 and up):
https://github.com/odoo/odoo/blob/13.0/odoo/tools/float_utils.py#L25
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
Whereas in Odoo 12.0 it was like this:
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"
if precision_digits is not None:
return 10 ** -precision_digits
return precision_rounding
So it looks like they added additional condition and precision_rounding
simply can not be equal to zero anymore - so you must specify positive number.
Easy fix would be to add a small number to it to ensure it is positive. Something like 0.01
should be fine as Odoo states that precision_rounding
can be float.
"""
:param int precision_digits: number of fractional digits to round to.
:param float precision_rounding: decimal number representing the minimum
non-zero value at the desired precision (for example, 0.01 for a
2-digit precision).
:param float value: value to compare with the precision's zero
:return: True if ``value`` is considered zero
"""
Upvotes: 1