From f964b761eae32016e36dd9d39cc2c35fc2270eba Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 8 Apr 2021 12:56:13 +0000 Subject: [WIP] hr_holidays: Leaves for partial time are wrongly counted Steps to reproduce the bug: - Let's consider an employee E that doesn't work on Monday morning - Create a half day leave request LR for E on a Monday afternoon - Save Bug: The duration of LR was counted as one day instead of 0.5 opw:2491784 closes odoo/odoo#68977 Signed-off-by: Simon Goffin (sig) --- addons/hr_holidays/models/hr_leave.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'addons/hr_holidays/models') diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index e3121f4532b..de259666d4f 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -594,7 +594,10 @@ 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_batch(date_from, date_to)[employee.id] + result = employee._get_work_days_data_batch(date_from, date_to)[employee.id] + if self.request_unit_half: + result['days'] = 0.5 + return result today_hours = self.env.company.resource_calendar_id.get_work_hours_count( datetime.combine(date_from.date(), time.min), @@ -602,8 +605,8 @@ class HolidaysRequest(models.Model): False) 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} + days = hours / (today_hours or HOURS_PER_DAY) if not self.request_unit_half else 0.5 + return {'days': days, 'hours': hours} def _adjust_date_based_on_tz(self, leave_date, hour): """ request_date_{from,to} are local to the user's tz but hour_{from,to} are in UTC. -- cgit v1.2.3