From 34ed6e22668a4dc4b0841f3badd549d0fb17895e Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Tue, 6 Dec 2022 11:52:07 +0000 Subject: [PATCH] [FIX] hr_holidays: apply timezone to leave statistics Context: In some companies, we want to give employees a day off. Unfortunately, their working hours do not correspond to those of the company. To remedy this, we set the work hours at: 00:00 until 23:59. Steps to reproduce: - set work hours to 00:00 until 23h59; - give one day off to a department; - view statistics on a employee (who belongs to the department). Issue: We notice that in the statistics, the dates are wrong. Indeed, it is indicated that the leave is over two days. Cause: When we receive the dates via the rpc call to display them, they are character strings. The browser interprets them with the computer's timezone (even if it is UTC). The hours of work being at the limit of the day, we overflow on a second day. Solution: As we know that the timezone used to store dates in the database is UTC, we can calculate an offset and apply it before displaying the result. opw-3063177 closes odoo/odoo#107614 X-original-commit: 31dda867957c8083177f7e2776fa461786c2bff3 Signed-off-by: Kevin Baptiste --- addons/hr_holidays/static/src/leave_stats/leave_stats.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/hr_holidays/static/src/leave_stats/leave_stats.js b/addons/hr_holidays/static/src/leave_stats/leave_stats.js index 54a4c684db3..1393fe4ef51 100644 --- a/addons/hr_holidays/static/src/leave_stats/leave_stats.js +++ b/addons/hr_holidays/static/src/leave_stats/leave_stats.js @@ -3,7 +3,7 @@ import { useService } from '@web/core/utils/hooks'; import { registry } from '@web/core/registry' -import { formatDate, parseDateTime } from "@web/core/l10n/dates"; +import { formatDate } from "@web/core/l10n/dates"; const { Component, useState, onWillStart, onWillUpdateProps } = owl; const { DateTime } = luxon; @@ -72,8 +72,8 @@ export class LeaveStatsComponent extends Component { this.state.departmentLeaves = departmentLeaves.map((leave) => { return Object.assign({}, leave, { - dateFrom: formatDate(parseDateTime(leave.date_from)), - dateTo: formatDate(parseDateTime(leave.date_to)), + dateFrom: formatDate(DateTime.fromSQL(leave.date_from, { zone: 'utc' }).toLocal()), + dateTo: formatDate(DateTime.fromSQL(leave.date_to, { zone: 'utc' }).toLocal()), sameEmployee: leave.employee_id[0] === employee[0], }); });