From 1e9b695ef16baf5e28915115fd34f72a2d767cf9 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 15 Mar 2017 14:45:13 +0100 Subject: [FIX] web: BasicModel: always reload x2many fields Before this commit, the relational data of a record was only fetched once, and then retrieved from the cache. This was premature optimization, that can lead to bugs as those relational data displayed in the webclient might be desynchronized with the actual data in DB. --- .../web/static/src/js/views/basic/basic_model.js | 49 ++++++++-------------- 1 file changed, 18 insertions(+), 31 deletions(-) (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 7d33d51257f..6c59d242cb0 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1300,7 +1300,6 @@ var BasicModel = AbstractModel.extend({ _fetchRecord: function (record, fieldNames) { var self = this; fieldNames = fieldNames || _.uniq(record.fieldNames.concat(['display_name'])); - var oldData = record.data; return this._rpc(record.model, 'read') .args([[record.res_id], fieldNames]) // .withContext({ bin_size: true }) // FIXME: when editing a subrecord in the partner form view, it tries to write the bin_size on the image field @@ -1313,7 +1312,7 @@ var BasicModel = AbstractModel.extend({ self._parseServerData(fieldNames, record.fields, record.data); }) .then(function () { - return self._fetchX2Manys(record, oldData, fieldNames).then(function () { + return self._fetchX2Manys(record, fieldNames).then(function () { return self._postprocess(record); }); }); @@ -1591,44 +1590,32 @@ var BasicModel = AbstractModel.extend({ * useless rpcs. * * @param {Object} record local resource - * @param {Object} oldData the data fetched previously * @param {string[]} [fieldNames] list of fields to fetch * @returns {Deferred} */ - _fetchX2Manys: function (record, oldData, fieldNames) { + _fetchX2Manys: function (record, fieldNames) { var self = this; var defs = []; fieldNames = fieldNames || record.fieldNames; _.each(fieldNames, function (fieldName) { var field = record.fields[fieldName]; if (field.type === 'one2many' || field.type === 'many2many') { - var list; - - // a previously loaded list exists - if (oldData[fieldName]) { - list = self.localData[oldData[fieldName]]; - list.res_ids = record.data[fieldName]; - list.count = list.res_ids.length; - list.offset = list.offset < list.count ? list.offset : 0; - } else { - // need to create a list from scratch - var attrs = record.fieldAttrs[fieldName]; - var rawContext = attrs && attrs.context; - var ids = record.data[fieldName] || []; - list = self._makeDataPoint({ - count: ids.length, - fieldAttrs: field.fieldAttrs, - fields: field.relatedFields, - limit: field.limit, - modelName: field.relation, - res_ids: ids, - static: true, - type: 'list', - parentID: record.id, - rawContext: rawContext, - relationField: field.relation_field, - }); - } + var attrs = record.fieldAttrs[fieldName]; + var rawContext = attrs && attrs.context; + var ids = record.data[fieldName] || []; + var list = self._makeDataPoint({ + count: ids.length, + fieldAttrs: field.fieldAttrs, + fields: field.relatedFields, + limit: field.limit, + modelName: field.relation, + res_ids: ids, + static: true, + type: 'list', + parentID: record.id, + rawContext: rawContext, + relationField: field.relation_field, + }); record.data[fieldName] = list.id; if (!field.__no_fetch) { var def = self._readUngroupedList(list).then(function () { -- cgit v1.2.3