diff options
| author | Géry Debongnie <ged@odoo.com> | 2017-12-07 15:33:52 +0100 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2017-12-07 16:20:46 +0100 |
| commit | 3b3f68030d29e74d3c2486921ed1b8868b1ba9c4 (patch) | |
| tree | aaa2c69f70f45c79210dee81ad77665d3ca1666c /addons/web/static/src/js/views/basic/basic_model.js | |
| parent | e193926db0a3430e56db8e4eeeade70a7ea511f6 (diff) | |
[FIX] web: send proper context when fetching m2o namegets
When fetching batched namegets (typically after a default_get), we need
to evaluate the context that we send to the server. This may be
important for models with a custom name_get method. (note: overriding
namegets should be avoided if possible)
With the new views refactoring, this was not done properly and the
'view' context was sent instead. This is not really critical, the proof
is that it took a few months before getting some complaints, but this is
definitely a bug.
To reproduce, simply add a context attribute to a m2o field in a form
view, with a non empty value in a default get, and look at the context
sent to the server.
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 | 26 |
1 files changed, 14 insertions, 12 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 e8f4a3993fa..416bc33f90f 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1724,22 +1724,21 @@ var BasicModel = AbstractModel.extend({ /** * Fetch all name_gets for the many2ones in a group * - * @param {Object} group a valid resource object + * @param {Object[]} groups a list of object with context and record sub keys * @returns {Deferred} */ - _fetchMany2OneGroup: function (group) { - var ids = _.uniq(_.pluck(group, 'res_id')); - + _fetchMany2OneGroup: function (groups) { + var ids = _.uniq(_.pluck(_.pluck(groups, 'record'), 'res_id')); return this._rpc({ - model: group[0].model, + model: groups[0].record.model, method: 'name_get', args: [ids], - context: group[0].context + context: groups[0].context }) .then(function (name_gets) { - _.each(group, function (record) { - var nameGet = _.find(name_gets, function (n) { return n[0] === record.res_id;}); - record.data.display_name = nameGet[1]; + _.each(groups, function (obj) { + var nameGet = _.find(name_gets, function (n) { return n[0] === obj.record.res_id;}); + obj.record.data.display_name = nameGet[1]; }); }); }, @@ -2000,14 +1999,17 @@ var BasicModel = AbstractModel.extend({ if (!relatedRecord) { return; } - toBeFetched.push(relatedRecord); + toBeFetched.push({ + context: record.getContext({fieldName: name, viewType: record.viewType}), + record: relatedRecord + }); } }); // group them by model and context. Using the context as key is // necessary to make sure the correct context is used for the rpc; - var groups = _.groupBy(toBeFetched, function (rec) { - return [rec.model, JSON.stringify(rec.context)].join(); + var groups = _.groupBy(toBeFetched, function (elem) { + return [elem.record.model, JSON.stringify(elem.context)].join(); }); return $.when.apply($, _.map(groups, this._fetchMany2OneGroup.bind(this))); |
