From bd004ac75e2249fded10e69c7e1d3bf5b5f64911 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 16 Oct 2018 11:54:10 +0000 Subject: [PATCH] [FIX] mail: chatter in x2many form view Since rev. 755a8d815a, it crashed when the user tried to open an x2many record in form view (thus in a dialog), if there was a chatter in that form's arch. This was because the wrong viewType was used (for instance, list or kanban instead of form), to look into fieldsInfo, and thus the chatter fields couldn't be found. opw 1891378 opw 1892520 opw 1893100 closes odoo/odoo#27844 --- addons/mail/static/src/js/chatter.js | 5 ++- addons/mail/static/src/js/form_renderer.js | 1 + addons/mail/static/tests/chatter_tests.js | 45 +++++++++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/addons/mail/static/src/js/chatter.js b/addons/mail/static/src/js/chatter.js index 780cd58deec..2f2e1a0e770 100644 --- a/addons/mail/static/src/js/chatter.js +++ b/addons/mail/static/src/js/chatter.js @@ -44,6 +44,9 @@ var Chatter = Widget.extend({ * @param {string} [mailFields.mail_activity] * @param {string} [mailFields.mail_followers] * @param {string} [mailFields.mail_thread] + * @param {Object} options + * @param {string} [options.viewType=record.viewType] current viewType in + * which the chatter is instantiated */ init: function (parent, record, mailFields, options) { this._super.apply(this, arguments); @@ -66,7 +69,7 @@ var Chatter = Widget.extend({ } if (mailFields.mail_thread) { this.fields.thread = new ThreadField(this, mailFields.mail_thread, record, options); - var fieldsInfo = this.record.fieldsInfo[record.viewType]; + var fieldsInfo = record.fieldsInfo[options.viewType || record.viewType]; var nodeOptions = fieldsInfo[mailFields.mail_thread].options || {}; this.hasLogButton = options.display_log_button || nodeOptions.display_log_button; this.postRefresh = nodeOptions.post_refresh || 'never'; diff --git a/addons/mail/static/src/js/form_renderer.js b/addons/mail/static/src/js/form_renderer.js index 21477f825c9..91d2c2033c4 100644 --- a/addons/mail/static/src/js/form_renderer.js +++ b/addons/mail/static/src/js/form_renderer.js @@ -54,6 +54,7 @@ FormRenderer.include({ if (!this.chatter) { this.chatter = new Chatter(this, this.state, this.mailFields, { isEditable: this.activeActions.edit, + viewType: 'form', }); this.chatter.appendTo($('
')); this._handleAttributes(this.chatter.$el, node); diff --git a/addons/mail/static/tests/chatter_tests.js b/addons/mail/static/tests/chatter_tests.js index c853ffb99e8..13e5d457545 100644 --- a/addons/mail/static/tests/chatter_tests.js +++ b/addons/mail/static/tests/chatter_tests.js @@ -1,7 +1,6 @@ odoo.define('mail.chatter_tests', function (require) { "use strict"; -var AttachmentBox = require('mail.AttachmentBox'); var mailTestUtils = require('mail.testUtils'); var concurrency = require('web.concurrency'); @@ -1126,6 +1125,50 @@ QUnit.test('chatter: discard changes on opening full-composer', function (assert form.destroy(); }); +QUnit.test('chatter in x2many form view', function (assert) { + // the purpose of this test is to ensure that it doesn't crash when a x2many + // record is opened in form view (thus in a dialog), and when there is a + // chatter in the arch (typically, this may occur when the view used for the + // x2many is a default one, which is also used in another context, as the + // chatter is hidden in the dialog anyway) + assert.expect(2); + + this.data.partner.fields.o2m = { + string: "one2many field", type: "one2many", relation: 'partner', + }; + this.data.partner.records[0].o2m = [2]; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + services: this.services, + arch: '
', + archs: { + 'partner,false,form': '
' + + '' + + '
' + + '' + + '
' + + '', + 'partner,false,list': '', + }, + res_id: 2, + viewOptions: { + mode: 'edit', + }, + }); + + form.$('.o_data_row:first').click(); + + assert.strictEqual($('.modal .o_form_view').length, 1, + "should have open a form view in a modal"); + assert.strictEqual($('.modal .o_chatter:visible').length, 0, + "chatter should be hidden (as in a dialog)"); + + form.destroy(); +}); + QUnit.test('chatter: Attachment viewer', function (assert) { assert.expect(6); this.data.partner.records[0].message_ids = [1];