[FIX] web: formview button context should be given to actions
When clicking on a stat button in a form view, an action is executed. The button might also be given a context which have to be used when running the action. This context was ignored since the context refactoring made with commit 26a7fe7de1b6258989bc63335321f8f8e83435af.
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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;
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -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:
|
||||
'<form string="Partners">' +
|
||||
'<sheet>' +
|
||||
'<div class="oe_button_box" name="button_box">' +
|
||||
'<button class="oe_stat_button" type="action" name="1" context="{\'test\': active_id}">' +
|
||||
'<field name="qux" widget="statinfo"/>' +
|
||||
'</button>' +
|
||||
'</div>' +
|
||||
'</sheet>' +
|
||||
'</form>',
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user