[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
This commit is contained in:
@@ -186,14 +186,14 @@
|
||||
<div t-attf-class="d-flex flex-column p-0 oe_kanban_card oe_kanban_global_click">
|
||||
<div class="o_kanban_content p-0 m-0 position-relative row d-flex flex-fill">
|
||||
<div class="col-3 text-bg-primary p-2 text-center d-flex flex-column justify-content-center">
|
||||
<div t-esc="record.date_begin.raw_value.getDate()" class="o_event_fontsize_20"/>
|
||||
<div t-esc="luxon.DateTime.fromISO(record.date_begin.raw_value).toFormat('d')" class="o_event_fontsize_20"/>
|
||||
<div>
|
||||
<t t-esc="luxon.DateTime.fromJSDate(record.date_begin.raw_value).toFormat('MMM yyyy')"/>
|
||||
<t t-esc="luxon.DateTime.fromISO(record.date_begin.raw_value).toFormat('MMM yyyy')"/>
|
||||
</div>
|
||||
<div><t t-esc="luxon.DateTime.fromJSDate(record.date_begin.raw_value).toFormat('t')"/></div>
|
||||
<div t-if="luxon.DateTime.fromJSDate(record.date_begin.raw_value).toFormat('DDMMYYYY') !== luxon.DateTime.fromJSDate(record.date_end.raw_value).toFormat('DDMMYYYY')">
|
||||
<div><t t-esc="luxon.DateTime.fromISO(record.date_begin.raw_value).toFormat('t')"/></div>
|
||||
<div t-if="record.date_begin.raw_value !== record.date_end.raw_value">
|
||||
<i class="fa fa-arrow-right me-2 o_event_fontsize_09" title="End date"/>
|
||||
<t t-esc="luxon.DateTime.fromJSDate(record.date_end.raw_value).toFormat('d MMM')"/>
|
||||
<t t-esc="luxon.DateTime.fromISO(record.date_end.raw_value).toFormat('d MMM')"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-9 py-2 px-3 d-flex flex-column justify-content-between pt-3">
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
</strong>
|
||||
</div>
|
||||
<div>
|
||||
<t t-if="new Date(record.expiration_date.raw_value) < (new Date())" t-set="expiration_class" t-value="'oe_kanban_text_red'"/>
|
||||
<t t-if="luxon.DateTime.fromISO(record.expiration_date.raw_value) < luxon.DateTime.local()" t-set="expiration_class" t-value="'oe_kanban_text_red'"/>
|
||||
<span t-att-class="expiration_class"><field name="start_date"/> - <field name="expiration_date"/></span>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<t t-if="record.comment.raw_value">
|
||||
<p class="o_kanban_record_subtitle"><em><field name="comment"/></em></p>
|
||||
</t>
|
||||
<p>Granted by <a type="open"><field name="create_uid" /></a> the <t t-esc="moment(record.create_date.raw_value).format('L')" /></p>
|
||||
<p>Granted by <a type="open"><field name="create_uid" /></a> the <t t-esc="luxon.DateTime.fromISO(record.create_date.raw_value).toFormat('D')" /></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -141,7 +141,7 @@
|
||||
<xpath expr="//li[@id='last_login']" position="inside">
|
||||
<span t-if="record.current_leave_id.raw_value" style="font-size: 100%"
|
||||
t-att-class="record.current_leave_state.raw_value=='validate'?'oe_kanban_button oe_kanban_color_3':'oe_kanban_button oe_kanban_color_2'"
|
||||
t-att-title="luxon.DateTime.fromJSDate(record.leave_date_from.raw_value).toFormat('ccc d MMM') + ' - ' + luxon.DateTime.fromJSDate(record.leave_date_to.raw_value).toFormat('ccc d MMM')">
|
||||
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')">
|
||||
<field name="current_leave_id"/>
|
||||
</span>
|
||||
</xpath>
|
||||
|
||||
@@ -465,7 +465,7 @@
|
||||
<t t-out="record.maintenance_open_count.raw_value"/> Request
|
||||
</div>
|
||||
<div class="badge text-bg-secondary" t-if="!selection_mode and record.next_action_date.raw_value" >
|
||||
<t t-esc="luxon.DateTime.fromJSDate(record.next_action_date.raw_value).toFormat('d MMMM')"/>
|
||||
<t t-esc="luxon.DateTime.fromISO(record.next_action_date.raw_value).toFormat('d MMMM')"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="oe_kanban_bottom_right">
|
||||
|
||||
@@ -224,7 +224,7 @@
|
||||
<field name="user_id" widget="many2one_avatar_user"
|
||||
options="{'display_avatar_name': True}"/>
|
||||
-
|
||||
<t t-esc="luxon.DateTime.fromJSDate(record.create_date.raw_value).toFormat('MMM yyyy')"/>
|
||||
<t t-esc="luxon.DateTime.fromISO(record.create_date.raw_value).toFormat('MMM yyyy')"/>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -112,7 +112,7 @@ function getRawValue(record, fieldName) {
|
||||
}
|
||||
case "date":
|
||||
case "datetime": {
|
||||
return value && value.toJSDate();
|
||||
return value && value.toISO();
|
||||
}
|
||||
default: {
|
||||
return value;
|
||||
|
||||
@@ -7140,8 +7140,11 @@ QUnit.module("Views", (hooks) => {
|
||||
"</kanban>",
|
||||
});
|
||||
|
||||
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) => {
|
||||
|
||||
Reference in New Issue
Block a user