From 1b2dab3f506d51b399625dba614dd3689e95bdc9 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Tue, 23 Aug 2016 14:42:46 +0200 Subject: [PATCH] [FIX] mail: preprocess tracking fields of type date/datetime only once Before this commit, if a message thread was loaded 2 times, the first time the date was well formatted, the second time that fail because momentjs cannot parse the localized date from some locale. Luckily, it was not bugged by default in english, because moment was able to reparse a localized US date. But in some local as french, momentjs cannot parse the localized date and return 'Invalid date' Now, we move the code, to be processed only once by the chat manager, and not in each process of the thread. This commit closes issue #13258 Courtesy of @aab-odoo --- addons/mail/static/src/js/chat_manager.js | 16 ++++++++++++++++ addons/mail/static/src/js/thread.js | 14 -------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js index 78f5547e6c8..02c4ce89852 100644 --- a/addons/mail/static/src/js/chat_manager.js +++ b/addons/mail/static/src/js/chat_manager.js @@ -282,6 +282,22 @@ function make_message (data) { a.url = '/web/content/' + a.id + '?download=true'; }); + // format date to the local only once by message + // can not be done in preprocess, since it alter the original value + if (msg.tracking_value_ids && msg.tracking_value_ids.length) { + _.each(msg.tracking_value_ids, function(f) { + if (_.contains(['date', 'datetime'], f.field_type)) { + var format = (f.field_type === 'date') ? 'LL' : 'LLL'; + if (f.old_value) { + f.old_value = moment.utc(f.old_value).local().format(format); + } + if (f.new_value) { + f.new_value = moment.utc(f.new_value).local().format(format); + } + } + }); + } + return msg; } diff --git a/addons/mail/static/src/js/thread.js b/addons/mail/static/src/js/thread.js index f0d5ae05339..ac4c50b4533 100644 --- a/addons/mail/static/src/js/thread.js +++ b/addons/mail/static/src/js/thread.js @@ -151,20 +151,6 @@ var Thread = Widget.extend({ msg.hour = msg.date.format('LT'); } - if (message.tracking_value_ids && message.tracking_value_ids.length) { - _.each(message.tracking_value_ids, function(f) { - if (_.contains(['date', 'datetime'], f.field_type)) { - var format = (f.field_type === 'date') ? 'LL' : 'LLL'; - if (f.old_value) { - f.old_value = moment.utc(f.old_value).local().format(format); - } - if (f.new_value) { - f.new_value = moment.utc(f.new_value).local().format(format); - } - } - }); - } - if (_.contains(this.expanded_msg_ids, message.id)) { msg.expanded = true; }