diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-04-26 15:44:40 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-26 16:35:18 +0200 |
| commit | d20074c555bf3b25155264d09ced81997eb632ff (patch) | |
| tree | 564a9ae3eca697e35a0a7594ffbf150b37000003 /addons/web/static/src/js/views/basic/basic_model.js | |
| parent | b9944978e90980d15d8ce170c986914f0490e240 (diff) | |
[FIX] web: BasicModel: don't mix fields and action contexts
The context sent when performing RPCs is a mix of several contexts
(user_context, action's context, context defined in a field's node
in an arch...).
In general, the action's context should not be mixed with the
field's context:
- for global RPCs (read a record, write a record, default_get...)
only the action's context should be given
- for RPCs triggered by fields (e.g. name_search in a m2o), only
the field's context should be sent.
The exception is for onchange RPCs, as in this case, both action
and field's contexts should be sent.
Before this rev, the action context was always sent, which might
produced tracebacks (e.g. go to Sales > My Pipeline > New > click
on Customer field > Create and Edit > boom).
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_model.js')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 23 |
1 files changed, 16 insertions, 7 deletions
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 d6cda54ef5d..ad9e3fbeed1 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1851,18 +1851,22 @@ var BasicModel = AbstractModel.extend({ * @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) + * 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 * @returns {Object} the evaluated context */ _getContext: function (element, options) { - var context = new Context(session.user_context, element.context); + options = options || {}; + var context = new Context(session.user_context); context.set_eval_context(this._getEvalContext(element)); - if (options && options.additionalContext) { - context.add(options.additionalContext); + if (options.full || !options.fieldName) { + context.add(element.context); } - if (options && options.fieldName) { + if (options.fieldName) { var viewType = options.viewType || element.viewType; var fieldInfo = element.fieldsInfo[viewType][options.fieldName]; if (fieldInfo && fieldInfo.context) { @@ -1874,6 +1878,9 @@ var BasicModel = AbstractModel.extend({ } } } + if (options.additionalContext) { + context.add(options.additionalContext); + } if (element.rawContext) { var rawContext = new Context(element.rawContext); var evalContext = this._getEvalContext(this.localData[element.parentID]); @@ -2319,7 +2326,9 @@ var BasicModel = AbstractModel.extend({ var self = this; var onchange_spec = this._buildOnchangeSpecs(record); var idList = record.data.id ? [record.data.id] : []; - var options = {}; + var options = { + full: true, + }; if (fields.length === 1) { fields = fields[0]; // if only one field changed, add its context to the RPC context |
