From efd158523438cebd96f9f2e7243873f222a97fea Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Tue, 18 Jul 2017 11:33:09 +0200 Subject: [PATCH] [FIX] web: fix action context Previously, we had to filter the context values to exclude some erroneous values we propagated earlier. This commit removes the earlier propagation of wrong values (the current record context when executing an action) and thus also removes the filtering of those values, which was actually removing useful values from the action context. The bug could be seen by following these steps: - Install crm and sale - Go to My Pipeline - Open an opportunity which has a customer set - Click on "New Quotation" action button - See that the customer is not set on the new quotation, it should be set by the default_partner_id value in the action context --- addons/web/static/src/js/chrome/view_manager.js | 3 ++- addons/web/static/src/js/views/basic/basic_model.js | 6 +++--- addons/web/static/tests/views/form_tests.js | 5 ++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/addons/web/static/src/js/chrome/view_manager.js b/addons/web/static/src/js/chrome/view_manager.js index fcd823f440a..b6208df272d 100644 --- a/addons/web/static/src/js/chrome/view_manager.js +++ b/addons/web/static/src/js/chrome/view_manager.js @@ -568,10 +568,11 @@ var ViewManager = Widget.extend(ControlPanelMixin, { // Wrong default_* and search_default_* values will no give the expected result // Wrong group_by values will simply fail and forbid rendering of the destination view var ncontext = new Context( - _.object(_.reject(_.pairs(_.extend({}, action_data.context, self.env.context)), function(pair) { + _.object(_.reject(_.pairs(self.env.context), function(pair) { return pair[0].match('^(?:(?:default_|search_default_|show_).+|.+_view_ref|group_by|group_by_no_leaf|active_id|active_ids)$') !== null; })) ); + ncontext.add(action_data.context || {}); ncontext.add({active_model: self.env.modelName}); if (res_ids) { ncontext.add({ diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index eead1b0aaed..75a0ad02971 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2369,8 +2369,8 @@ var BasicModel = AbstractModel.extend({ * if given, this field's context is added to the context, instead of * the element's context (except if options.full is true) * @param {boolean} [options.full=false] - * if true and fieldName given in options, the element's context - * is added to the context + * if true or nor fieldName or additionalContext given in options, + * the element's context is added to the context * @returns {Object} the evaluated context */ _getContext: function (element, options) { @@ -2378,7 +2378,7 @@ var BasicModel = AbstractModel.extend({ var context = new Context(session.user_context); context.set_eval_context(this._getEvalContext(element)); - if (options.full || !options.fieldName) { + if (options.full || !(options.fieldName || options.additionalContext)) { context.add(element.context); } if (options.fieldName) { diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index fd395892e31..86c32b4971d 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -3519,10 +3519,13 @@ QUnit.module('Views', { '' + '', res_id: 2, + viewOptions: { + context: {some_context: true}, + }, intercepts: { execute_action: function (e) { assert.deepEqual(e.data.action_data.context, {test: 2}, - "button context should have been evaluated and given to the action"); + "button context should have been evaluated and given to the action, without previous context"); }, }, });