From 3a0f9da0ebf5d8438effd2f656b87b64cbe5237a Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Mon, 29 Oct 2018 14:10:06 +0000 Subject: [PATCH] [FIX] web: load SubViews without previous' view _view_ref context keys On a form view (of model A), define a many2one (model B) with a [form|tree]_view_ref context key In that view, have a x2m field (model C) with a different [form|tree]_view_ref context key Before this commit, the second load_views (i.e. on the model C) crashed because the wrong context key was sent to the server, which returned the view to which the _view_ref points i.e. the view of the model B After this commit, we clean the context of subviews loading, because those keys are only useful for the python and one shot. Hence, there is no crash OPW 1903780 closes odoo/odoo#28260 --- .../web/static/src/js/views/view_dialogs.js | 5 +- .../static/tests/views/view_dialogs_tests.js | 55 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/view_dialogs.js b/addons/web/static/src/js/views/view_dialogs.js index f16317a29e3..163131d47f3 100644 --- a/addons/web/static/src/js/views/view_dialogs.js +++ b/addons/web/static/src/js/views/view_dialogs.js @@ -168,9 +168,12 @@ var FormViewDialog = ViewDialog.extend({ if (self.recordID) { self.model.addFieldsInfo(self.recordID, viewInfo); } + var refinedContext = _.pick(self.context, function (value, key) { + return key.indexOf('_view_ref') === -1; + }); var formview = new FormView(viewInfo, { modelName: self.res_model, - context: self.context, + context: refinedContext, ids: self.res_id ? [self.res_id] : [], currentId: self.res_id || undefined, index: 0, diff --git a/addons/web/static/tests/views/view_dialogs_tests.js b/addons/web/static/tests/views/view_dialogs_tests.js index e45b4c13c83..b18c552830f 100644 --- a/addons/web/static/tests/views/view_dialogs_tests.js +++ b/addons/web/static/tests/views/view_dialogs_tests.js @@ -365,6 +365,61 @@ QUnit.module('Views', { form.destroy(); }); + QUnit.test('Form dialog and subview with _view_ref contexts', function (assert) { + assert.expect(2); + + this.data.instrument.records = [{id: 1, name: 'Tromblon', badassery: [1]}]; + this.data.partner.records[0].instrument = 1; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '', + res_id: 1, + archs: { + 'instrument,false,form': '
'+ + ''+ + '' + + '', + + 'badassery,false,list': ''+ + ''+ + '', + }, + viewOptions: { + mode: 'edit', + }, + + mockRPC: function(route, args) { + if (args.method === 'get_formview_id') { + return $.when(false); + } + return this._super(route, args); + }, + + interceptsPropagate: { + load_views: function (ev) { + var evaluatedContext = ev.data.context.eval(); + if (ev.data.modelName === 'instrument') { + assert.deepEqual(evaluatedContext, {tree_view_ref: 'some_tree_view'}, + 'The correct _view_ref should have been sent to the server, first time'); + } + if (ev.data.modelName === 'badassery') { + assert.deepEqual(evaluatedContext, {tree_view_ref: 'some_other_tree_view'}, + 'The correct _view_ref should have been sent to the server for the subview'); + } + }, + }, + }); + + form.$('.o_field_widget[name="instrument"] button.o_external_button').click(); + form.destroy(); + }); + }); });