summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorlen-odoo <len@odoo.com>2018-12-07 08:59:23 +0000
committerAaron Bohy <aab@odoo.com>2018-12-19 13:03:46 +0000
commit9186f433f1f4847646700d2289d0d8aad489bf48 (patch)
tree16cffc0cf78f522187c2e61268afcdf359193ef4 /addons/web/static/src/js
parent3d119415a2e87b75abf8fbd77ace538cdf18a112 (diff)
[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
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js21
1 files changed, 17 insertions, 4 deletions
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];