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];