From 28bf5f007fd777f7cf2c8f85ea9938b288d391f0 Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Mon, 31 Jul 2017 14:48:50 +0200 Subject: [PATCH] [FIX] web: fix action context with no explicit context When I did efd15852, I accidentally undid d20074c5. That commit wanted to filter out unwanted values from the action context, but it was too violent, as it was discarding the action context. (See bug described in efd15852) My original commit aimed at avoiding the filtering of the action context by having it devoid of unwanted values altogether. The idea was "if this is an action button, we don't want the element context". However, the default behavior of the _getContext function was to add the element context. There were options to force to add the element context despite being in a case where it should not be added, but we needed the opposite: do not add the element context. We used "additionalContext" in this fashion, the idea was: "if I give you specific context values, don't polute it with the element context". This was efd15852. However, not all actions have context defined explicitely in their definition. In this case, since additionalContext was undefined, the element context was added again, despite our will not to add it for actions. We solved this by simply always giving an additionalContext to getContext, providing an empty one if needed. To reproduce this bug (which is the same as efd15852): - Go to Manufacturing - Click on menu Master Data then Products - Open a product - Click on the "Bills of Materials" stat button - Click on create - The create crashes because of the "default_type" context key that is erroneously passed from the "Products" action to the "Bills of Materials" stat button action. --- .../src/js/views/basic/basic_controller.js | 2 +- addons/web/static/tests/views/form_tests.js | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js index 54c8ccfbf51..39e596db5b8 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -238,7 +238,7 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { var recordID = record.data.id; this.trigger_up('execute_action', { action_data: _.extend({}, attrs, { - context: record.getContext({additionalContext: attrs.context}), + context: record.getContext({additionalContext: attrs.context || {}}), }), model: record.model, res_ids: [recordID], diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index 65c19818118..2a08a305fd0 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -3572,6 +3572,40 @@ QUnit.module('Views', { form.destroy(); }); + QUnit.test('clicking on a stat button with no context', function (assert) { + assert.expect(1); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: + '
' + + '' + + '
' + + '' + + '
' + + '
' + + '
', + res_id: 2, + viewOptions: { + context: {some_context: true}, + }, + intercepts: { + execute_action: function (e) { + assert.deepEqual(e.data.action_data.context, {}, + "button context should have been evaluated and given to the action, without previous context"); + }, + }, + }); + + form.$('.oe_stat_button').click(); + + form.destroy(); + }); + QUnit.test('diplay a stat button outside a buttonbox', function (assert) { assert.expect(3);