From d62e7d9af4d9e298ca67e6e214180960b7cf05f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Tue, 15 Mar 2022 13:03:32 +0000 Subject: [PATCH] [IMP] turn "Message/datetime" into field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-2793280 closes odoo/odoo#86448 Signed-off-by: Alexandre Kühn (aku) --- .../static/src/components/message/message.js | 10 ---------- .../static/src/components/message/message.xml | 2 +- addons/mail/static/src/models/message.js | 18 +++++++++++++++++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/addons/mail/static/src/components/message/message.js b/addons/mail/static/src/components/message/message.js index 85732388e8c..b3efd700d4b 100644 --- a/addons/mail/static/src/components/message/message.js +++ b/addons/mail/static/src/components/message/message.js @@ -8,7 +8,6 @@ import { isEventHandled, markEventHandled } from '@mail/utils/utils'; import { _lt } from 'web.core'; import Popover from "web.Popover"; -import { getLangDatetimeFormat } from 'web.time'; const { Component, onWillUnmount, useRef, useState } = owl; @@ -86,15 +85,6 @@ export class Message extends Component { // Public //-------------------------------------------------------------------------- - /** - * Get the date time of the message at current user locale time. - * - * @returns {string} - */ - get datetime() { - return this.messageView.message.date.format(getLangDatetimeFormat()); - } - /** * Whether the message is "active", ie: hovered or clicked, and should * display additional things (date in sidebar, message actions, etc.) diff --git a/addons/mail/static/src/components/message/message.xml b/addons/mail/static/src/components/message/message.xml index efc34d3690d..ed6b6ea99ae 100644 --- a/addons/mail/static/src/components/message/message.xml +++ b/addons/mail/static/src/components/message/message.xml @@ -83,7 +83,7 @@ -
+
-
diff --git a/addons/mail/static/src/models/message.js b/addons/mail/static/src/models/message.js index d83270485ab..96b19cbea5f 100644 --- a/addons/mail/static/src/models/message.js +++ b/addons/mail/static/src/models/message.js @@ -9,7 +9,7 @@ import { addLink, htmlToTextContentInline, parseAndTransform, timeFromNow } from import { session } from '@web/session'; import { format } from 'web.field_utils'; -import { str_to_datetime } from 'web.time'; +import { getLangDatetimeFormat, str_to_datetime } from 'web.time'; registerModel({ name: 'Message', @@ -383,6 +383,16 @@ registerModel({ } return timeFromNow(this.date); }, + /** + * @private + * @returns {string|FieldCommand} + */ + _computeDatetime() { + if (!this.date) { + return clear(); + } + return this.date.format(getLangDatetimeFormat()); + }, /** * @returns {boolean} */ @@ -717,6 +727,12 @@ registerModel({ dateFromNow: attr({ compute: '_computeDateFromNow', }), + /** + * The date time of the message at current user locale time. + */ + datetime: attr({ + compute: '_computeDatetime', + }), email_from: attr(), failureNotifications: many('Notification', { compute: '_computeFailureNotifications',