From a21e2593ceba35faab216859375da5cf5951d3a6 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 14 Apr 2017 23:40:18 +0200 Subject: [PATCH] [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. --- .../static/src/js/fields/relational_fields.js | 2 +- .../tests/fields/relational_fields_tests.js | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 4c05946cf23..06f38abffbb 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -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; diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 4f06bc93bee..6b23940a9db 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -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: '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
', + 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) {