[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
This commit is contained in:
Aaron Bohy
2018-10-17 08:44:49 +00:00
parent a1e052a4b4
commit bd004ac75e
3 changed files with 49 additions and 2 deletions
+4 -1
View File
@@ -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';
@@ -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);
+44 -1
View File
@@ -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: '<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];