From 047e2b28de4653f11e097e6232d7fb79d54ce3af Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 11 Dec 2018 12:34:24 +0000 Subject: [PATCH] [FIX] mail: keep context when sending a message When sending a message through the chatter, the user context (including the language) is not sent to the server. This causes issues to render the mail templates in the appropriate language. closes odoo/odoo#29422 --- .../src/js/composers/chatter_composer.js | 3 +- addons/mail/static/tests/chatter_tests.js | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/js/composers/chatter_composer.js b/addons/mail/static/src/js/composers/chatter_composer.js index cda91eab205..777467e6eb8 100644 --- a/addons/mail/static/src/js/composers/chatter_composer.js +++ b/addons/mail/static/src/js/composers/chatter_composer.js @@ -3,6 +3,7 @@ odoo.define('mail.composer.Chatter', function (require) { var BasicComposer = require('mail.composer.Basic'); var mailUtils = require('mail.utils'); +var session = require('web.session'); var core = require('web.core'); var viewDialogs = require('web.view_dialogs'); @@ -195,7 +196,7 @@ var ChatterComposer = BasicComposer.extend({ message = _.extend(message, { subtype: 'mail.mt_comment', message_type: 'comment', - context: self.context, + context: _.defaults({}, self.context, session.user_context), }); // Subtype diff --git a/addons/mail/static/tests/chatter_tests.js b/addons/mail/static/tests/chatter_tests.js index 4bcce4ab352..e13d5f18202 100644 --- a/addons/mail/static/tests/chatter_tests.js +++ b/addons/mail/static/tests/chatter_tests.js @@ -1451,6 +1451,55 @@ QUnit.test('chatter: Attachment viewer', function (assert) { form.destroy(); }); +QUnit.test('chatter: keep context when sending a message', function(assert) { + assert.expect(1); + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + services: this.services, + arch: '
' + + '' + + '' + + '' + + '
' + + '' + + '
' + + '
', + res_id: 2, + session: { + user_context: {lang: 'en_US'}, + }, + mockRPC: function (route, args) { + if (args.method === 'message_get_suggested_recipients') { + return $.when({2: []}); + } + if (args.method === 'message_post') { + assert.deepEqual(args.kwargs.context, { + default_model: "partner", + default_res_id: 2, + lang: "en_US", + mail_post_autofollow: true, + }, + "the context is incorrect"); + return $.when(57923); + } + if (args.method === 'message_format') { + return $.when([{ + author_id: [42, "Me"], + model: 'partner', + }]); + } + return this._super(route, args); + }, + }); + + testUtils.dom.click(form.$('.o_chatter_button_new_message')); + testUtils.fields.editInput(form.$('.oe_chatter .o_composer_text_field:first()'), 'Pouet'); + testUtils.dom.click(form.$('.oe_chatter .o_composer_button_send')); + form.destroy(); +}); + QUnit.test('form activity widget: read RPCs', function (assert) { // Records of model 'mail.activity' may be updated in business flows (e.g. // the date of a 'Meeting' activity is updated when the associated meeting