2

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

Yasmine
  • 123
  • 8

1 Answers1

1

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
"""
AnJ
  • 581
  • 1
  • 6
  • 29
  • Same issue `precision_rounding must be positive, got 0` ,actually i did add a condition `if precision_rounding == 0 : precision_rounding += 0.01` it's working but i don't know it's legal – Yasmine Jul 15 '21 at 09:31
  • 1
    Yeah I've just checked the source code and it looks like Odoo changed the way it checks this parameter. So I updated my answer. You can add `0.01` and it should be perfectly fine. – AnJ Jul 15 '21 at 09:43
  • Thank you for answering me ,actually i just did it on my own ,i thought i was wrong – Yasmine Jul 15 '21 at 10:25
  • Funny part, that's how the field `rounding` is defined on model `res.currency`: `rounding = fields.Float(string='Rounding Factor', digits=(12, 6), default=0.01)`. Default value is `0.01`, so this answer can be considered correct. – CZoellner Jul 15 '21 at 13:18
  • I didn't think about it, when i wrote my first comment, but that's pure logically, because the rounding is meant as a positional definition. For example `0.01` means round the value to second decimal position, where `0.0001` means to round at the fourth decimal. So `0.0` wouldn't define a position at all, but `1.0` should work, too. – CZoellner Jul 15 '21 at 13:21