From 27dd19c0b9b5ccdf1e84509119ace6becb09ff6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 11 Jan 2018 15:24:56 +0100 Subject: [FIX] web: prevent crash in some rare cases When we have a form view with a one2many with an onchange, and with lines which contains a x2many, and more lines that the limit (so more than one page), and the read is not in the same order as what is displayed because we have a widget=handle, then we might have a problem when we delete one of the lines, if the onchanges tries to change the x2many. This is due to the fact that the order of the basicmodel datapoint is not preserved by the various operations going around. I think that we may still have a few other issues of this type, but it is actually quite difficult to establish. In any case, this situation is now properly handled. opw 804530 --- addons/web/static/src/js/views/basic/basic_model.js | 2 +- 1 file changed, 1 insertion(+), 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 3621b7c1227..a94e2fe9454 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2374,7 +2374,7 @@ var BasicModel = AbstractModel.extend({ }); record.data[fieldName] = list.id; if (!fieldInfo.__no_fetch) { - var def = self._readUngroupedList(list).then(function () { + var def = self._readUngroupedList(list).then(function (list) { return $.when( self._fetchX2ManysBatched(list), self._fetchReferencesBatched(list) -- cgit v1.2.3 From 41fe7f9d1113d026b226b136b4477aaaf9f1f638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Ku=CC=88hn?= Date: Tue, 9 Jan 2018 12:04:21 +0100 Subject: [FIX] web: contexts on field widgets + enforce bin_size for binary Field widgets now have a key 'context' that let them extend the context of the dataPoint (e.g. list). In particular, widgets on binary fields enforce the contextual item {bin_size: True}, so that the server gives the size of the binary field as its value, instead of its content. This change on binary fields reduces network load when accessing a view with binary fields. --- .../web/static/src/js/views/basic/basic_model.js | 43 +++++++++++++++++++--- 1 file changed, 38 insertions(+), 5 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 a94e2fe9454..a6979776c99 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -33,7 +33,7 @@ odoo.define('web.BasicModel', function (require) { * isOpen: {boolean}, * loadMoreOffset: {integer}, * limit: {integer}, - * model: {string, + * model: {string}, * offset: {integer}, * openGroupByDefault: {boolean}, * orderedBy: {Object[]}, @@ -1854,7 +1854,7 @@ var BasicModel = AbstractModel.extend({ model: record.model, method: 'read', args: [[record.res_id], fieldNames], - context: _.extend({}, record.getContext(), {bin_size: true}), + context: record.getContext(), }) .then(function (result) { if (result.length === 0) { @@ -3040,10 +3040,33 @@ var BasicModel = AbstractModel.extend({ * the resource in the localData object. * * @param {Object} params + * @param {Object} [params.aggregateValues={}] + * @param {Object} [params.context={}] context of the action + * @param {integer} [params.count=0] number of record being manipulated + * @param {Object|Object[]} [params.data={}|[]] data of the record + * @param {*[]} [params.domain=[]] + * @param {Object} params.fields contains the description of each field * @param {Object} [params.fieldsInfo={}] contains the fieldInfo of each field - * @param {Array} [params.fieldNames] the name of fields to load, the list + * @param {Object[]} [params.fieldNames] the name of fields to load, the list * of all fields by default - * @param {Object} params.fields contains the description of each field + * @param {string[]} [params.groupedBy=[]] + * @param {boolean} [params.isOpen] + * @param {integer} params.limit max number of records shown on screen (pager size) + * @param {string} params.modelName + * @param {integer} [params.offset] + * @param {boolean} [params.openGroupByDefault] + * @param {Object[]} [params.orderedBy=[]] + * @param {integer[]} [params.orderedResIDs] + * @param {string} [params.parentID] model name ID of the parent model + * @param {Object} [params.rawContext] + * @param {[type]} [params.ref] + * @param {string} [params.relationField] + * @param {integer|null} [params.res_id] actual id of record in the server + * @param {integer[]} [params.res_ids] context in which the data point is used, from a list of res_id + * @param {boolean} [params.static=false] + * @param {string} [params.type='record'|'list'] + * @param {[type]} [params.value] + * @param {string} [params.viewType] the type of the view, e.g. 'list' or 'form' * @returns {Object} the resource created */ _makeDataPoint: function (params) { @@ -3069,13 +3092,23 @@ var BasicModel = AbstractModel.extend({ id: {type: 'integer'}, }, params.fields); + // datapoint context is extended by fields widgets + var context = _.extend({}, params.context); + if (params.fieldsInfo && params.viewType) { + _.each(params.fieldsInfo[params.viewType], function (field) { + if (field.context) { + _.extend(context, field.context); + } + }); + } + var dataPoint = { _cache: type === 'list' ? {} : undefined, _changes: null, _domains: {}, _rawChanges: {}, aggregateValues: params.aggregateValues || {}, - context: params.context || {}, + context: context, count: params.count || res_ids.length, data: data, domain: params.domain || [], -- cgit v1.2.3