[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 <kba@odoo.com> Signed-off-by: Thomas Lefebvre (thle) <thle@odoo.com>
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user