From 8ac98fc78a3794e06481b02a431bcdc386a5a6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Mon, 14 May 2018 21:18:32 +0200 Subject: [FIX] web: show names of many2one on default_get Before this commit, some records in a list did not show the name of their many2one fields. This case occurs when the records in the list are created from a default_get, and the records do not fit in a single page. In that case, the records in the first page correctly display the names of their many2one fields, but not the records in the other pages. Fixes #24547 --- .../web/static/src/js/views/basic/basic_model.js | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') 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 a90cc1075c9..60c167ddfd1 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2469,7 +2469,16 @@ var BasicModel = AbstractModel.extend({ var self = this; var def; if (list.static) { - def = this._readUngroupedList(list); + def = this._readUngroupedList(list).then(function () { + if (list.parentID && self.isNew(list.parentID)) { + // list from a default_get, so fetch display_name for many2one fields + var many2ones = self._getMany2OneFieldNames(list); + var defs = _.map(many2ones, function (name) { + return self._fetchNameGets(list, name); + }); + return $.when.apply($, defs); + } + }); } else { def = this._searchReadUngroupedList(list); } @@ -3037,6 +3046,23 @@ var BasicModel = AbstractModel.extend({ var viewType = options && options.viewType || element.viewType; return Object.keys(fieldsInfo && fieldsInfo[viewType] || {}); }, + /** + * Get many2one fields names in a datapoint. This is useful in order to + * fetch their names in the case of a default_get. + * + * @private + * @param {Object} datapoint a valid resource object + * @returns {string[]} list of field names that are many2one + */ + _getMany2OneFieldNames: function (datapoint) { + var many2ones = []; + _.each(datapoint.fields, function (field, name) { + if (field.type === 'many2one') { + many2ones.push(name); + } + }); + return many2ones; + }, /** * Evaluate the record evaluation context. This method is supposed to be * called by _getEvalContext. It basically only generates a dictionary of -- cgit v1.2.3