[FIX] web: FieldX2Many: don't ignore mode attribute

The 'mode' attribute can be used for x2many fields to force the
view mode. Before this rev., it was ignored and if a tree view
existed in the view description, it was selected by default.

This was mainly a problem in mobile as in this case, kanban views
are prefered, and the data_manager forces the mode to be kanban,
so the data was fetched according to the kanban view fields, but
later on the list view was instantiated instead of kanban by the
x2many field, so it crashed if both views didn't share the exact
same fields.
This commit is contained in:
Aaron Bohy
2017-04-15 15:00:05 +02:00
committed by Géry Debongnie
parent f6c20c61d6
commit a21e2593ce
2 changed files with 35 additions and 1 deletions
@@ -532,7 +532,7 @@ var FieldX2Many = AbstractField.extend({
this._super.apply(this, arguments);
this.operations = [];
this.isReadonly = this.mode === 'readonly';
this.view = this.attrs.views.list || this.attrs.views.kanban;
this.view = this.attrs.views[this.attrs.mode];
this.activeActions = {};
this.recordParams = {fieldName: this.name, viewType: this.viewType};
var arch = this.view && this.view.arch;
@@ -2737,6 +2737,40 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('x2many fields use their "mode" attribute', function (assert) {
assert.expect(1);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<group>' +
'<field mode="kanban" name="turtles">' +
'<tree>' +
'<field name="turtle_foo"/>' +
'</tree>' +
'<kanban>' +
'<templates>' +
'<t t-name="kanban-box">' +
'<div>' +
'<field name="turtle_int"/>' +
'</div>' +
'</t>' +
'</templates>' +
'</kanban>' +
'</field>' +
'</group>' +
'</form>',
res_id: 1,
});
assert.strictEqual(form.$('.o_form_field_one2many .o_kanban_view').length, 1,
"should have rendered a kanban view");
form.destroy();
});
QUnit.module('FieldMany2Many');
QUnit.test('many2many kanban: edition', function (assert) {