Skip to content
Permalink
Browse files

[FIX] hr_holidays: numerical error

In some exceptional circumstances, the computation of the remaining
leaves might lead to numerical errors, e.g. a very small but non-zero
number (e.g. 10^-17)

This value will be displayed in the name of the leave type because of
the `%g` used in the string format. To avoid breaking the translation,
we round the value.

opw-1935232

closes #31245
  • Loading branch information...
nim-odoo committed Feb 19, 2019
1 parent 29a3634 commit bddd53881c6ea8d7870717e77961aff1f8920167
Showing with 5 additions and 2 deletions.
  1. +5 −2 addons/hr_holidays/models/hr_holidays.py
@@ -9,7 +9,7 @@

from odoo import api, fields, models
from odoo.exceptions import UserError, AccessError, ValidationError
from odoo.tools import float_compare
from odoo.tools import float_compare, float_round
from odoo.tools.translate import _

_logger = logging.getLogger(__name__)
@@ -120,7 +120,10 @@ def name_get(self):
if not record.limit:
name = "%(name)s (%(count)s)" % {
'name': name,
'count': _('%g remaining out of %g') % (record.virtual_remaining_leaves or 0.0, record.max_leaves or 0.0)
'count': _('%g remaining out of %g') % (
float_round(record.virtual_remaining_leaves or 0.0, precision_digits=2) + 0.0,
record.max_leaves or 0.0
)
}
res.append((record.id, name))
return res

0 comments on commit bddd538

Please sign in to comment.
You can’t perform that action at this time.