From 3b3f68030d29e74d3c2486921ed1b8868b1ba9c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 7 Dec 2017 15:33:52 +0100 Subject: [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. --- .../web/static/src/js/views/basic/basic_model.js | 26 ++++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'addons/web/static/src/js/views/basic') 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))); -- cgit v1.2.3 From 6c024d1ef0c9e828b09eea17f55748784232a0c9 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Thu, 7 Dec 2017 09:10:39 +0100 Subject: [FIX] web: give context to fetch x2m batched Before this commit M2Mtags widget did not translate. This was because no context was given to the rpc that fetched the fields Hence, the lang was not passed. After this commit, M2Mtags translate well OPW 784396 --- addons/web/static/src/js/views/basic/basic_model.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src/js/views/basic') 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 416bc33f90f..1562bffdc42 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1480,7 +1480,8 @@ var BasicModel = AbstractModel.extend({ def = this._rpc({ model: list.model, method: 'read', - args: [_.pluck(data, 'id'), fieldNames] + args: [_.pluck(data, 'id'), fieldNames], + context: record.context, }).then(function (records) { _.each(records, function (record) { list_records[record.id].data = record; @@ -2399,7 +2400,7 @@ var BasicModel = AbstractModel.extend({ model: field.relation, method: 'read', args: [ids, fieldNames], - context: {}, // FIXME + context: list.getContext() || {}, }); } else { def = $.when(_.map(ids, function (id) { -- cgit v1.2.3