From 0e69cd996d5986e4a7eced2ffe8dd00250130bce Mon Sep 17 00:00:00 2001 From: jbm-odoo Date: Fri, 3 May 2019 09:50:05 +0000 Subject: [PATCH] [IMP] hr_holidays: Compute real hours The number of hours in time off were computed based on a mean of number of hours in a week. It can engendre problem if an employee doesn't work with the same number of hours every day. Now the number of hours are computed based on employee's calendar and so the real number of hours are used. closes odoo/odoo#33137 Signed-off-by: Yannick Tivisse (yti) --- addons/hr_holidays/models/hr_leave.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 4a3d2be8666..5ad7df34797 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -378,7 +378,7 @@ class HolidaysRequest(models.Model): @api.onchange('date_from', 'date_to', 'employee_id') def _onchange_leave_dates(self): if self.date_from and self.date_to: - self.number_of_days = self._get_number_of_days(self.date_from, self.date_to, self.employee_id.id) + self.number_of_days = self._get_number_of_days(self.date_from, self.date_to, self.employee_id.id)['days'] else: self.number_of_days = 0 @@ -398,7 +398,7 @@ class HolidaysRequest(models.Model): for holiday in self: calendar = holiday._get_calendar() if holiday.date_from and holiday.date_to: - number_of_hours = calendar.get_work_hours_count(holiday.date_from, holiday.date_to) + number_of_hours = holiday._get_number_of_days(holiday.date_from, holiday.date_to, holiday.employee_id.id)['hours'] holiday.number_of_hours_display = number_of_hours or (holiday.number_of_days * HOURS_PER_DAY) else: holiday.number_of_hours_display = 0 @@ -466,14 +466,16 @@ class HolidaysRequest(models.Model): """ Returns a float equals to the timedelta between two dates given as string.""" if employee_id: employee = self.env['hr.employee'].browse(employee_id) - return employee._get_work_days_data(date_from, date_to)['days'] + return employee._get_work_days_data(date_from, date_to) today_hours = self.env.company.resource_calendar_id.get_work_hours_count( datetime.combine(date_from.date(), time.min), datetime.combine(date_from.date(), time.max), False) - return self.env.company.resource_calendar_id.get_work_hours_count(date_from, date_to) / (today_hours or HOURS_PER_DAY) + hours = self.env.company.resource_calendar_id.get_work_hours_count(date_from, date_to) + + return {'days': hours / (today_hours or HOURS_PER_DAY), 'hours': hours} #################################################### # ORM Overrides methods