From e062f89ed50c962197288a4e25f508fd5b3395bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 29 Nov 2018 15:07:47 +0000 Subject: [FIX] web: prevent crash in some cases (o2m) Recent works in the orm (see [1] for example) changed the behaviour of the server in the case of onchanges: it tries to optimize Odoo by sending a minimal diff to the web client in onchanges. Concretely, this means that the web client receives commands 4 (link to) instead of command 1 (update + record data). It also sends a minimal diff in that case. This is a big issue for the web client, because it relied on the knowledge of the data from the command 1 to be able to evaluate some modifiers. The good news is that we can mitigate the issue in one case: we do not actually need to evaluate the modifiers in the case of a command 4 (comming from the server), because we can assume that the record is valid. So, we simply bypass the check in that case. Note that this should fix most of the problem, but a deeper problem still remains: a crash can still happen when an onchange modifies a record in a one2many (but in a different page), and we also have a modifier which needs to be evaluated. opw: #1904514 [1] https://github.com/odoo/odoo/pull/29086 closes odoo/odoo#29172 closes odoo/odoo#29086 --- addons/web/static/src/js/views/basic/basic_model.js | 1 + 1 file changed, 1 insertion(+) (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 04a10b46442..508ece9af0d 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -3208,6 +3208,7 @@ var BasicModel = AbstractModel.extend({ _.each(element._changes, function (command) { if (command.operation === 'DELETE' || command.operation === 'FORGET' || + (command.operation === 'ADD' && !command.isNew)|| command.operation === 'REMOVE_ALL') { return; } -- cgit v1.2.3 From ddc5cc186fc6e2efa92fea6a83ad4bbed72d648c Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Tue, 18 Dec 2018 12:01:22 +0000 Subject: [FIX] web: call _applyX2ManyChange with the correct viewtype Have a one2many display records in a kanban subview, which opens a form view when edited. Edit a field displayed only on the form view. A call to _applyX2ManyChange is done without giving it the viewtype argument, therefore the fieldinfo is taken from the wrong view, traceback ensues. opw 1914163 closes odoo/odoo#29607 --- addons/web/static/src/js/views/basic/basic_model.js | 4 ++-- 1 file changed, 2 insertions(+), 2 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 cc923642047..c9e28db86c6 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1937,7 +1937,7 @@ var BasicModel = AbstractModel.extend({ addDef = this._applyX2ManyChange(record, fieldName, { operation: 'ADD_M2M', ids: values - }); + }, viewType); } if (removedIds.length) { var listData = _.map(list.data, function (localId) { @@ -1951,7 +1951,7 @@ var BasicModel = AbstractModel.extend({ } return _.findWhere(listData, {res_id: resID}).id; }), - }); + }, viewType); } return $.when(addDef, removedDef); } -- cgit v1.2.3 From 4abdfc35d30510b04d1d88a7add74efc591d9236 Mon Sep 17 00:00:00 2001 From: svs-odoo Date: Thu, 13 Dec 2018 10:44:32 +0000 Subject: [FIX] web: wait many2many tags' fetches for rendering Before this commit, we don't assure fetch's deferreds were resolved to return _readGroup. Thus, in some conditions, kanban was rendered before records data was updated so many2many tags could be missing. Now, we return _readGroup when fetch's deferreds were resolved. Task #1910805 closes odoo/odoo#29508 --- addons/web/static/src/js/views/basic/basic_model.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 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 8266b1dee42..fecbaa5b90c 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -4289,9 +4289,12 @@ var BasicModel = AbstractModel.extend({ } return list; }).then(function () { - self._fetchX2ManysSingleBatch(list); - self._fetchReferencesSingleBatch(list); - return list; + var fetchingDefs = []; + fetchingDefs.push(self._fetchX2ManysSingleBatch(list)); + fetchingDefs.push(self._fetchReferencesSingleBatch(list)); + return $.when.apply($, fetchingDefs).then(function () { + return list; + }); }); }); }, -- cgit v1.2.3 From 9186f433f1f4847646700d2289d0d8aad489bf48 Mon Sep 17 00:00:00 2001 From: len-odoo Date: Fri, 7 Dec 2018 08:59:23 +0000 Subject: [FIX] web: read records up to list limit Fine-tuning of commit e7fab234201e357da52c3576ad2e8fc9ceee9359 In a one2many with more than one page with a limit of k records, add a line l. It increments the list limit to k+1. Remove a line above (of index <= k). It will try to load a line l' to replace it, that it will find on page 2. However when deciding if it should read missing fields on that record, it will scan at most u records, skipping virtual ids. Here u is the min between the current number of lines and the list limit without the temporary increase due to the added record. Since there are at least two pages, u = k. However since l is in the list at index k, then l' won't be read, and since it was on page 2 its data hasn't been loaded. Therefore the js would traceback when trying to evaluate it. opw 1913361 closes odoo/odoo#29338 --- addons/web/static/src/js/views/basic/basic_model.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 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 508ece9af0d..418542e062a 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -3958,11 +3958,24 @@ var BasicModel = AbstractModel.extend({ } return def.then(function () { var resIDs = []; - // generate the current count and res_ids list by applying the changes - var currentCount = list.count; var currentResIDs = list.res_ids; - var effectiveLimit = (list.limit || 0) - (list.tempLimitIncrement || 0); - var upperBound = effectiveLimit ? Math.min(list.offset + effectiveLimit, currentCount) : currentCount; + // if new records have been added to the list, their virtual ids have + // been pushed at the end of res_ids (or at the beginning, depending + // on the editable property), ignoring completely the current page + // where the records have actually been created ; for that reason, + // we use orderedResIDs which is a freezed order with the virtual ids + // at the correct position where they were actually inserted ; however, + // when we use orderedResIDs, we must filter out ids that are not in + // res_ids, which correspond to records that have been removed from + // the relation (this information being taken into account in res_ids + // but not in orderedResIDs) + if (list.orderedResIDs) { + currentResIDs = list.orderedResIDs.filter(function (resID) { + return list.res_ids.indexOf(resID) >= 0; + }); + } + var currentCount = currentResIDs.length; + var upperBound = list.limit ? Math.min(list.offset + list.limit, currentCount) : currentCount; var fieldNames = list.getFieldNames(); for (var i = list.offset; i < upperBound; i++) { var resId = currentResIDs[i]; -- cgit v1.2.3 From 3125d20da30b972aa845d7f0884876b4ae2e6f1c Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Wed, 2 Jan 2019 15:17:12 +0000 Subject: [FIX] web: X2Many read propagates field context Most operations on X2Many widget possibly propagates a field context (name_create, name_search, ...) but the original read or read on an onchange does not. With this changeset, the field context is also used in these instances. The assertions added in the added test failed with: expected: ["world"], result: [undefined] expected: ["world","world"], result: [undefined,undefined] fixes #29203 opw-1914466 closes #29866 --- addons/web/static/src/js/views/basic/basic_model.js | 4 ++-- 1 file changed, 2 insertions(+), 2 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 418542e062a..1a6e21c4049 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1701,7 +1701,7 @@ var BasicModel = AbstractModel.extend({ model: list.model, method: 'read', args: [_.pluck(data, 'id'), fieldNames], - context: record.context, + context: _.extend({}, record.context, field.context), }).then(function (records) { _.each(records, function (record) { list_records[record.id].data = record; @@ -2543,7 +2543,7 @@ var BasicModel = AbstractModel.extend({ var ids = record.data[fieldName] || []; var list = self._makeDataPoint({ count: ids.length, - context: record.context, + context: _.extend({}, record.context, field.context), fieldsInfo: fieldsInfo, fields: view ? view.fields : fieldInfo.relatedFields, limit: fieldInfo.limit, -- cgit v1.2.3