From de6292759ea3e95e1f440950f75b6eb35a2c1e7b Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur <nle@odoo.com> Date: Thu, 1 Jul 2021 10:14:59 +0000 Subject: [PATCH] [FIX] hr_holidays: request date tz whole company When setting the request_date_from and request_date_to when creating a leave that will be used to show the range of days of the leaves, we are using the current user timezone to determine it. eg. in UTC+2 if the leave begins at midnight on the 6th, we will see 6 and not 5 which is the day in UTC. When creating a leave in a mode different than employee, when it is confirmed and a leave is created for each employee, we would use the UTC day instead which is a little unexpected. Without the fix, the added test fails with: AssertionError: datetime.date(2019, 5, 5) != datetime.date(2019, 5, 6) : Timezone should be kept between company and employee leave opw-2573730 closes odoo/odoo#73073 Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com> --- addons/hr_holidays/models/hr_leave.py | 4 ++-- .../hr_holidays/tests/test_leave_requests.py | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 8642f44f99e8..fc615b84239b 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -693,8 +693,8 @@ class HolidaysRequest(models.Model): 'holiday_status_id': self.holiday_status_id.id, 'date_from': self.date_from, 'date_to': self.date_to, - 'request_date_from': self.date_from, - 'request_date_to': self.date_to, + 'request_date_from': self.request_date_from, + 'request_date_to': self.request_date_to, 'notes': self.notes, 'number_of_days': employee.get_work_days_data(self.date_from, self.date_to)['days'], 'parent_id': self.id, diff --git a/addons/hr_holidays/tests/test_leave_requests.py b/addons/hr_holidays/tests/test_leave_requests.py index f38b58f4cfca..15593be4cbf0 100644 --- a/addons/hr_holidays/tests/test_leave_requests.py +++ b/addons/hr_holidays/tests/test_leave_requests.py @@ -214,6 +214,27 @@ class TestLeaveRequests(TestHrHolidaysBase): self.assertEqual(leave.date_from, datetime(2019, 5, 5, 20, 0, 0), "It should have been localized before saving in UTC") self.assertEqual(leave.date_to, datetime(2019, 5, 6, 5, 0, 0), "It should have been localized before saving in UTC") + @mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail') + def test_timezone_department_validated(self): + """ Create a department leave """ + self.env.user.tz = 'NZ' # GMT+12 + company = self.env['res.company'].create({'name': "Hergé"}) + employee = self.env['hr.employee'].create({'name': "Remi", 'company_id': company.id}) + leave_form = Form(self.env['hr.leave']) + leave_form.holiday_type = 'company' + leave_form.mode_company_id = company + leave_form.holiday_status_id = self.holidays_type_1 + leave_form.request_date_from = date(2019, 5, 6) + leave_form.request_date_to = date(2019, 5, 6) + leave = leave_form.save() + leave.state = 'confirm' + leave.action_validate() + employee_leave = self.env['hr.leave'].search([('employee_id', '=', employee.id)]) + self.assertEqual( + employee_leave.request_date_from, date(2019, 5, 6), + "Timezone should be kept between company and employee leave" + ) + @mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail') def test_timezone_department_leave_request(self): """ Create a leave request for a department in another timezone """ -- GitLab