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 5f934ea4e65..dc0beb96942 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1714,6 +1714,8 @@ var BasicModel = AbstractModel.extend({ * * @param {Object} element an element from the localData * @param {Object} [options] + * @param {string|Object} [options.additionalContext] + * another context to evaluate and merge to the returned context * @param {string} [options.fieldName] * the name of the field whose context needs to be added to the * result (and evaluated) @@ -1723,6 +1725,9 @@ var BasicModel = AbstractModel.extend({ var context = new Context(session.user_context, element.context); context.set_eval_context(this._getEvalContext(element)); + if (options && options.additionalContext) { + context.add(options.additionalContext); + } if (options && options.fieldName) { var viewType = options.viewType || element.viewType; var fieldInfo = element.fieldsInfo[viewType][options.fieldName]; diff --git a/addons/web/static/src/js/views/form/form_controller.js b/addons/web/static/src/js/views/form/form_controller.js index d41ff592687..7de919a0c2c 100644 --- a/addons/web/static/src/js/views/form/form_controller.js +++ b/addons/web/static/src/js/views/form/form_controller.js @@ -270,7 +270,7 @@ var FormController = BasicController.extend({ var recordID = record.data.id; this.trigger_up('execute_action', { action_data: _.extend({}, attrs, { - context: _.extend(record.getContext(), attrs.context), + context: record.getContext({additionalContext: attrs.context}), }), model: record.model, record_id: recordID, @@ -579,4 +579,3 @@ var FormController = BasicController.extend({ return FormController; }); - diff --git a/addons/web/static/test/views/form_tests.js b/addons/web/static/test/views/form_tests.js index e40bb20c139..637fba747e1 100644 --- a/addons/web/static/test/views/form_tests.js +++ b/addons/web/static/test/views/form_tests.js @@ -2222,5 +2222,36 @@ QUnit.module('Views', { form.destroy(); }); + + QUnit.test('clicking on a stat button with a context', function (assert) { + assert.expect(1); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: + '
', + res_id: 2, + 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"); + }, + }, + }); + + form.$('.oe_stat_button').click(); + + form.destroy(); + }); }); });