diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-06-23 14:06:03 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-06-27 14:12:31 +0200 |
| commit | 4881f942cb7cad51b8472425830c8444cfe09d1a (patch) | |
| tree | 870af496c0b031bd75d6cae6dd14d2b43b77280c /addons/web/static/src/js/views/basic/basic_model.js | |
| parent | 17e198153ecfd9c5c32b3b22f43e2f1b8100a1c3 (diff) | |
[FIX] web: BasicModel: correctly eval x2manys in domains
When x2many fields have to be evaluated in domains (e.g. ['id',
'in', some_x2many_field]), they must be evaluated as the list of
ids in the relation (whereas in contexts, they are evaluated as a
list of commands). Before this rev., they were always evaluated as
a list of commands.
Note that this didn't work neither before the new views.
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 | 24 |
1 files changed, 16 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 7e4c5927503..1001ac73857 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2248,14 +2248,14 @@ var BasicModel = AbstractModel.extend({ if (fieldInfo && fieldInfo.domain) { return Domain.prototype.stringToArray( fieldInfo.domain, - this._getEvalContext(element) + this._getEvalContext(element, true) ); } var fieldParams = element.fields[options.fieldName]; if (fieldParams.domain) { return Domain.prototype.stringToArray( fieldParams.domain, - this._getEvalContext(element) + this._getEvalContext(element, true) ); } return []; @@ -2263,7 +2263,7 @@ var BasicModel = AbstractModel.extend({ return Domain.prototype.stringToArray( element.domain, - this._getEvalContext(element) + this._getEvalContext(element, true) ); }, /** @@ -2275,10 +2275,12 @@ var BasicModel = AbstractModel.extend({ * sure. This allows some domains to use the uid key for example * * @param {Object} element - an element from the localData + * @param {boolean} [forDomain=false] if true, evaluates x2manys as a list of + * ids instead of a list of commands * @returns {Object} */ - _getEvalContext: function (element) { - var evalContext = element.type === 'record' ? this._getRecordEvalContext(element) : {}; + _getEvalContext: function (element, forDomain) { + var evalContext = element.type === 'record' ? this._getRecordEvalContext(element, forDomain) : {}; if (element.parentID) { var parent = this.localData[element.parentID]; @@ -2286,7 +2288,7 @@ var BasicModel = AbstractModel.extend({ parent = this.localData[parent.parentID]; } if (parent.type === 'record') { - evalContext.parent = this._getRecordEvalContext(parent); + evalContext.parent = this._getRecordEvalContext(parent, forDomain); } } return _.extend({ @@ -2314,9 +2316,11 @@ var BasicModel = AbstractModel.extend({ * current values for the record, with commands for x2manys fields. * * @param {Object} record an element of type 'record' + * @param {boolean} [forDomain=false] if true, x2many values are a list of + * ids instead of a list of commands * @returns Object */ - _getRecordEvalContext: function (record) { + _getRecordEvalContext: function (record, forDomain) { var self = this; var relDataPoint; var context = _.extend({}, record.data, record._changes); @@ -2349,7 +2353,11 @@ var BasicModel = AbstractModel.extend({ if (field.type === 'one2many' || field.type === 'many2many') { relDataPoint = this._applyX2ManyOperations(this.localData[context[fieldName]]); var ids = relDataPoint.res_ids.slice(0); - ids.toJSON = _generateX2ManyCommands.bind(null, fieldName); + if (!forDomain) { + // when sent to the server, the x2manys values must be a list + // of commands in a context, but the list of ids in a domain + ids.toJSON = _generateX2ManyCommands.bind(null, fieldName); + } context[fieldName] = ids; } |
