From 20ba16e7770ed2da8f7c19baafc8f380a5d995b1 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Fri, 15 Jul 2016 12:22:55 +0200 Subject: [PATCH] [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 --- addons/hr_holidays/hr_holidays.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index 73b1a0afe4d..5ad9492085a 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -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.'))