[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 <kba@odoo.com>
This commit is contained in:
Thomas Lefebvre (thle)
2022-12-09 14:08:07 +01:00
parent 7705690621
commit 34ed6e2266
@@ -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],
});
});