diff options
| author | qsm-odoo <qsm@odoo.com> | 2017-02-24 17:08:45 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 167db67300fde595b9017f90ab87494db37adc6b (patch) | |
| tree | 75bce0a3dac94985b470bcad32e33956e27914d1 /addons/web/static/src/js/views/basic/basic_model.js | |
| parent | 352cc10348d784b5276c44358bb3d0af8b108db3 (diff) | |
[FIX] web: _getContext was not returning a consistent context
Hopefully, this commit makes it consistent. There were two problems
with the previous implementation:
- Contexts from field attr (if asked thanks to the options.field
parameter) were not evaluated with the right evaluation ctx
- "raw" contexts (from parent) had to be evaluated with another
evaluation context
Also rename the options.field parameter to options.fieldName.
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 | 21 |
1 files changed, 13 insertions, 8 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 54a95f69500..4413168cc73 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1564,24 +1564,29 @@ var BasicModel = AbstractModel.extend({ * * @param {Object} element an element from the localData * @param {Object} [options] - * @param {string} [options.field] if given, the context of the field will - * also be added (and evaluated) to the result + * @param {string} [options.fieldName] + * the name of the field whose context needs to be added to the + * result (and evaluated) * @returns {Object} the evaluated context */ _getContext: function (element, options) { var context = new Context(session.user_context, element.context); - if (options && options.field) { - var attrs = element.fieldAttrs[options.field]; + context.set_eval_context(element.data); + if (options && options.fieldName) { + var attrs = element.fieldAttrs[options.fieldName]; if (attrs && attrs.context) { context.add(attrs.context); } } + if (element.rawContext) { - context.add(element.rawContext); + var rawContext = new Context(element.rawContext); var evalContext = this.get(element.parentID, {raw: true}).data; evalContext.id = evalContext.id || false; - context.set_eval_context(evalContext); + rawContext.set_eval_context(evalContext); + context.add(rawContext); } + return context.eval(); }, /** @@ -1701,7 +1706,7 @@ var BasicModel = AbstractModel.extend({ }).then(function (result) { var ids = _.pluck(result.records, 'id'); return self.performModelRPC(field.relation, 'name_get', [ids], { - context: self._getContext(record, {field: name}), + context: self._getContext(record, {fieldName: name}), }).then(function (name_gets) { _.each(result.records, function (record) { var name_get = _.find(name_gets, function (n) { @@ -1717,7 +1722,7 @@ var BasicModel = AbstractModel.extend({ if (field.__always_reload) { if (record.data[name] instanceof Array) { defs.push(self.performModelRPC(field.relation, 'name_get', [record.data[name][0]], { - context: self._getContext(record, {field: name}), + context: self._getContext(record, {fieldName: name}), }).then(function (result) { record.data[name] = result[0]; })); |
