From 78ac0865399e10e6352bd14aec8d660d32fac60a Mon Sep 17 00:00:00 2001 From: Bruno Boi Date: Thu, 1 Sep 2022 12:59:10 +0000 Subject: [PATCH] [REF] web,*: raw_value as ISO8601 in kanban templates This commit will make date(time) raw_value an ISO string instead of a native JS Date. - Before this commit In kanban templates: - the raw_value property of a record's date/datetime field is a native JS Date object. The problem with raw_value is that JS Dates toString method depends on the system locale and timezone. In the code base, the usage of raw_value for date/datetime fields usually parse the raw_value into a luxon DateTime object in order generally to display it in a specific format, or in order to compare it to another luxon DateTime object (e.g. the now instant). - After this commit The raw_value property of a record's date/datetime field has become an ISO8601 string, instead of native JSDate toString format (which I recall depends on system's locale and timezone). The ISO8601 format is easier to work with. Part-of: odoo/odoo#98980 --- addons/event/views/event_event_views.xml | 10 +++++----- addons/fleet/views/fleet_vehicle_cost_views.xml | 2 +- .../views/gamification_badge_user_views.xml | 2 +- addons/hr_holidays/views/hr_views.xml | 2 +- addons/maintenance/views/maintenance_views.xml | 2 +- addons/survey/views/survey_survey_views.xml | 2 +- addons/web/static/src/views/kanban/kanban_record.js | 2 +- addons/web/static/tests/views/kanban_view_tests.js | 7 +++++-- 8 files changed, 16 insertions(+), 13 deletions(-) diff --git a/addons/event/views/event_event_views.xml b/addons/event/views/event_event_views.xml index 29ba55782ee..480a2f43c79 100644 --- a/addons/event/views/event_event_views.xml +++ b/addons/event/views/event_event_views.xml @@ -186,14 +186,14 @@
-
+
- +
-
-
+
+
- +
diff --git a/addons/fleet/views/fleet_vehicle_cost_views.xml b/addons/fleet/views/fleet_vehicle_cost_views.xml index d4d0a76f913..a215180e825 100644 --- a/addons/fleet/views/fleet_vehicle_cost_views.xml +++ b/addons/fleet/views/fleet_vehicle_cost_views.xml @@ -111,7 +111,7 @@
- + -
diff --git a/addons/gamification/views/gamification_badge_user_views.xml b/addons/gamification/views/gamification_badge_user_views.xml index a4ab16719a9..0539325db30 100644 --- a/addons/gamification/views/gamification_badge_user_views.xml +++ b/addons/gamification/views/gamification_badge_user_views.xml @@ -25,7 +25,7 @@

-

Granted by the

+

Granted by the

diff --git a/addons/hr_holidays/views/hr_views.xml b/addons/hr_holidays/views/hr_views.xml index 521f605992b..9c3364495ef 100644 --- a/addons/hr_holidays/views/hr_views.xml +++ b/addons/hr_holidays/views/hr_views.xml @@ -141,7 +141,7 @@ + t-att-title="luxon.DateTime.fromISO(record.leave_date_from.raw_value).toFormat('ccc d MMM') + ' - ' + luxon.DateTime.fromISO(record.leave_date_to.raw_value).toFormat('ccc d MMM')"> diff --git a/addons/maintenance/views/maintenance_views.xml b/addons/maintenance/views/maintenance_views.xml index 5241d2f99b8..474ac62a444 100644 --- a/addons/maintenance/views/maintenance_views.xml +++ b/addons/maintenance/views/maintenance_views.xml @@ -465,7 +465,7 @@ Request
- +
diff --git a/addons/survey/views/survey_survey_views.xml b/addons/survey/views/survey_survey_views.xml index 499ae4120ca..9a7fb3192bb 100644 --- a/addons/survey/views/survey_survey_views.xml +++ b/addons/survey/views/survey_survey_views.xml @@ -224,7 +224,7 @@ - - +
diff --git a/addons/web/static/src/views/kanban/kanban_record.js b/addons/web/static/src/views/kanban/kanban_record.js index 1359ddf48ca..2c0d2cd95a5 100644 --- a/addons/web/static/src/views/kanban/kanban_record.js +++ b/addons/web/static/src/views/kanban/kanban_record.js @@ -112,7 +112,7 @@ function getRawValue(record, fieldName) { } case "date": case "datetime": { - return value && value.toJSDate(); + return value && value.toISO(); } default: { return value; diff --git a/addons/web/static/tests/views/kanban_view_tests.js b/addons/web/static/tests/views/kanban_view_tests.js index b76ccc7ab5c..2eb66a9286c 100644 --- a/addons/web/static/tests/views/kanban_view_tests.js +++ b/addons/web/static/tests/views/kanban_view_tests.js @@ -7140,8 +7140,11 @@ QUnit.module("Views", (hooks) => { "", }); - assert.ok(getCard(0).querySelector(".date").innerText.startsWith("Wed Jan 25 2017")); - assert.ok(getCard(1).querySelector(".datetime").innerText.startsWith("Mon Dec 12 2016")); + assert.equal(getCard(0).querySelector(".date").innerText, "2017-01-25T00:00:00.000+01:00"); + assert.equal( + getCard(1).querySelector(".datetime").innerText, + "2016-12-12T11:55:05.000+01:00" + ); }); QUnit.test("rendering many2one (value)", async (assert) => {