Skip to content

Commit

Permalink
[FIX] mail: chatter in x2many form view
Browse files Browse the repository at this point in the history
Since rev. 755a8d8, 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
  • Loading branch information
aab-odoo committed Oct 17, 2018
1 parent 6d3477c commit 08e6dc9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
5 changes: 4 additions & 1 deletion addons/mail/static/src/js/chatter.js
Expand Up @@ -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);
Expand All @@ -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';
Expand Down
1 change: 1 addition & 0 deletions addons/mail/static/src/js/form_renderer.js
Expand Up @@ -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($('<div>'));
this._handleAttributes(this.chatter.$el, node);
Expand Down
45 changes: 44 additions & 1 deletion 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');
Expand Down Expand Up @@ -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: '<form><field name="o2m"/></form>',
archs: {
'partner,false,form': '<form>' +
'<field name="foo"/>' +
'<div class="oe_chatter">' +
'<field name="message_ids" widget="mail_thread"/>' +
'</div>' +
'</form>',
'partner,false,list': '<tree><field name="display_name"/></tree>',
},
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];
Expand Down

0 comments on commit 08e6dc9

Please sign in to comment.