From bfbf92d4f59f5c869e9806b152d2975f2f57d03e Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Wed, 28 Jun 2023 11:16:13 +0000 Subject: [PATCH] [FIX] hr_holidays: correct iso format sent to the frontend Steps to reproduce: ------------------- - go to Time Off / Configuration / Public Holidays; - create a public holiday (for one day): start = 00:00:00 end = 23:59:59 - go to Time Off dashboard. Issue: ------ The description of this public holiday is not correct. The display shows that the public holiday is two days instead of one. Cause: ------ When recording a public holiday, dates are saved in UTC. Depending on the offset (UTC offset), this can change the day. When we send the date in iso format to the frontend, we modify the hours, but not the day. Solution: --------- Apply the employee's timezone to the datetime object before sending it to the frontend. Note: ----- The correction is on the server side, as we use the `combine` method of the datetime object before sending the result to the frontend. Indeed, we modify the times and lose the information needed to apply the timezone afterwards. opw-3381894 closes odoo/odoo#126983 X-original-commit: 1268502b813d9b9173edb3851faef965df6be6fe Signed-off-by: Kevin Baptiste Signed-off-by: Thomas Lefebvre (thle) --- addons/hr_holidays/models/hr_employee.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/hr_holidays/models/hr_employee.py b/addons/hr_holidays/models/hr_employee.py index 95fcb35b708..27e2ae69bc1 100644 --- a/addons/hr_holidays/models/hr_employee.py +++ b/addons/hr_holidays/models/hr_employee.py @@ -3,6 +3,7 @@ import datetime from dateutil.relativedelta import relativedelta +import pytz from odoo import _, api, fields, models from odoo.exceptions import UserError @@ -295,14 +296,15 @@ class HrEmployee(models.Model): @api.model def get_public_holidays_data(self, date_start, date_end): self = self._get_contextual_employee() + employee_tz = pytz.timezone(self._get_tz() if self else self.env.user.tz) public_holidays = self._get_public_holidays(date_start, date_end).sorted('date_from') return list(map(lambda bh: { 'id': -bh.id, 'colorIndex': 0, - 'end': datetime.datetime.combine(bh.date_to, datetime.datetime.max.time()).isoformat(), + 'end': datetime.datetime.combine(bh.date_to.astimezone(employee_tz), datetime.datetime.max.time()).isoformat(), 'endType': "datetime", 'isAllDay': True, - 'start': datetime.datetime.combine(bh.date_from, datetime.datetime.min.time()).isoformat(), + 'start': datetime.datetime.combine(bh.date_from.astimezone(employee_tz), datetime.datetime.min.time()).isoformat(), 'startType': "datetime", 'title': bh.name, }, public_holidays))