[FIX] hr_holidays: compare correctly floats

As the number of holidays are float, we may get a flloating point error when
comparing and having -0.0000000001 instead of 0 for the number of remaining
leaves, making the test fail.

Closes #12809
Fixes #14643
This commit is contained in:
Alexis de Lattre 2016-07-15 12:22:55 +02:00 committed by Martin Trigaux
parent 23ed2805b8
commit 20ba16e777
No known key found for this signature in database
GPG Key ID: 7B0E288E7C0F83A7
1 changed files with 3 additions and 1 deletions

View File

@ -29,6 +29,7 @@ from operator import attrgetter
from openerp.exceptions import Warning
from openerp import tools
from openerp.osv import fields, osv
from openerp.tools import float_compare
from openerp.tools.translate import _
@ -460,7 +461,8 @@ class hr_holidays(osv.osv):
if record.holiday_type != 'employee' or record.type != 'remove' or not record.employee_id or record.holiday_status_id.limit:
continue
leave_days = self.pool.get('hr.holidays.status').get_days(cr, uid, [record.holiday_status_id.id], record.employee_id.id, context=context)[record.holiday_status_id.id]
if leave_days['remaining_leaves'] < 0 or leave_days['virtual_remaining_leaves'] < 0:
if float_compare(leave_days['remaining_leaves'], 0, precision_digits=2) == -1 or \
float_compare(leave_days['virtual_remaining_leaves'], 0, precision_digits=2) == -1:
# Raising a warning gives a more user-friendly feedback than the default constraint error
raise Warning(_('The number of remaining leaves is not sufficient for this leave type.\n'
'Please verify also the leaves waiting for validation.'))