[FIX] hr_holidays: don't assume default date strings are datetimes
Versions
--------
- saas-16.3+
Steps
-----
1. Set timezone of User and browser to America/Los_Angeles;
2. go to Time Off;
3. click on calendar to create a new leave.
Issue
-----
Date defaults to the day before the selected date.
Cause
-----
Commit 0a0c6917b5 added a TZ conversion in
JS to add default start & end times for leaves. The issue is that it
assumes the context values are always datetime strings, therefore always
using `deserializeDateTime`, which does a timezone conversion from UTC
to local time, which is incorrect when the context values are date
strings.
For a UTC-7 zone like America/Los_Angeles, it deserializes a date string
like '2024-01-01' to '2023-12-12 17:00:00' (7 hours before midnight). It
then sets the start hour to 7, and serializes it back to UTC, adding 7
hours, resulting in '2023-12-12 14:00:00'. Instead, Jan 1, 7 AM in
America/Los_Angeles should convert to '2024-01-01 14:00:00' UTC.
Solution
--------
Use `deserializeDate` instead of `deserializeDateTime` when the
`default_date_{from,to}` in the context is a date rather than a
datetime. This way, '2024-01-01' gets deserialized into '2024-01-01
00:00:00' local time. When this value gets used for the default hours,
'2024-01-01 07:00:00' local time will get serialized to '2024-01-01
14:00:00' UTC as expected.
opw-3757712
closes odoo/odoo#162203
X-original-commit: 134455167734d101a8ce923043700e5fc8f497bd
Signed-off-by: Levi Siuzdak <sile@odoo.com>
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { CalendarModel } from '@web/views/calendar/calendar_model';
|
||||
import { deserializeDateTime, serializeDate, serializeDateTime } from "@web/core/l10n/dates";
|
||||
import {
|
||||
deserializeDate,
|
||||
deserializeDateTime,
|
||||
serializeDate,
|
||||
serializeDateTime,
|
||||
} from "@web/core/l10n/dates";
|
||||
|
||||
export class TimeOffCalendarModel extends CalendarModel {
|
||||
setup(params, services) {
|
||||
@@ -31,14 +36,18 @@ export class TimeOffCalendarModel extends CalendarModel {
|
||||
context["default_employee_id"] = this.employeeId;
|
||||
}
|
||||
|
||||
function deserialize(str) {
|
||||
// "YYYY-MM-DD".length == 10
|
||||
return str.length > 10 ? deserializeDateTime(str) : deserializeDate(str);
|
||||
}
|
||||
if ("default_date_from" in context) {
|
||||
context["default_date_from"] = serializeDateTime(
|
||||
deserializeDateTime(context["default_date_from"]).set({ hours: 7 })
|
||||
deserialize(context["default_date_from"]).set({ hours: 7 })
|
||||
);
|
||||
}
|
||||
if ("default_date_to" in context) {
|
||||
context["default_date_to"] = serializeDateTime(
|
||||
deserializeDateTime(context["default_date_to"]).set({ hours: 19 })
|
||||
deserialize(context["default_date_to"]).set({ hours: 19 })
|
||||
);
|
||||
}
|
||||
return context;
|
||||
|
||||
Reference in New Issue
Block a user