From 217fee2636fb4dc4c193e67e5727a9fcef200605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Thu, 7 Jun 2018 15:55:54 +0200 Subject: [FIX] web: prevent RPC from failing if no route is set The scenario is: - create a new parent model, which has a one2many - add at least 2 one2many lines which have: - a handle field - a many2one, which is not required, and we will leave it empty - reorder the lines with the handle This will call a resequence, which calls a name_get. With the bug that would throw an error at the RPC, but this commit fixes it. --- addons/web/static/src/js/views/basic/basic_model.js | 16 +++++++++++++++- 1 file changed, 15 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 cf3c08128ce..ae9f0611abf 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1984,9 +1984,20 @@ var BasicModel = AbstractModel.extend({ dataPoint.data.display_name = result[0][1]; }); }, + /** + * Fetch name_get for a field of type Many2one or Reference + * + * @private + * @params {Object} list: must be a datapoint of type list + * (for example: a datapoint representing a x2many) + * @params {string} fieldName: the name of a field of type Many2one or Reference + * @returns {Deferred} + */ _fetchNameGets: function (list, fieldName) { var self = this; - var model; + // We first get the model this way because if list.data is empty + // the _.each below will not make it. + var model = list.fields[fieldName].relation; var records = []; var ids = []; list = this._applyX2ManyOperations(list); @@ -1999,8 +2010,11 @@ var BasicModel = AbstractModel.extend({ var many2oneRecord = self.localData[many2oneId]; records.push(many2oneRecord); ids.push(many2oneRecord.res_id); + // We need to calculate the model this way too because + // field .relation is not set for a reference field. model = many2oneRecord.model; }); + if (!ids.length) { return $.when(); } -- cgit v1.2.3