From e7fab234201e357da52c3576ad2e8fc9ceee9359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Wed, 7 Mar 2018 14:02:14 +0100 Subject: [FIX] web: better experience for one2many edition (paged) A big problem with the o2m edition happens when the user has a full page (so, in general, 40 records) and click on add. If the o2m is in editable="bottom" mode (which is actually a really common usecase), then the next record will be added at the end. However, since we have a limit of 40, it will immediately go to the next page. The effect is even weirder when there is a required field in the tree view. In that case, the new record appears correctly, the user can edit it, then, as soon as the required fields are set, it will immediately disappear from the current screen. In this commit, we have a really simple solution: we simply increase the limit in this case. An interesting thing is that it is actually temporary: when the user goes to the next page, the limit is back to its original value (due to the pager click: it resets the value to what the pager knows). --- addons/web/static/src/js/views/basic/basic_model.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/views/basic') 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 c8bd4ae030f..f081d0a6caa 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -809,6 +809,7 @@ var BasicModel = AbstractModel.extend({ this.discardChanges(id, {rollback: false}); } } else if (element._changes) { + delete element.tempLimitIncrement; _.each(element._changes, function (change) { delete change.isNew; }); @@ -1683,6 +1684,10 @@ var BasicModel = AbstractModel.extend({ case 'CREATE': var options = {position: command.position}; def = this._addX2ManyDefaultRecord(list, options).then(function (id) { + if (command.position === 'bottom' && list.orderedResIDs.length >= list.limit) { + list.tempLimitIncrement = (list.tempLimitIncrement || 0) + 1; + list.limit += 1; + } // FIXME: hack for lunch widget, which does useless default_get and onchange if (command.data) { return self._applyChange(id, command.data); @@ -3819,7 +3824,8 @@ var BasicModel = AbstractModel.extend({ // generate the current count and res_ids list by applying the changes var currentCount = list.count; var currentResIDs = list.res_ids; - var upperBound = list.limit ? Math.min(list.offset + list.limit, currentCount) : currentCount; + var effectiveLimit = (list.limit || 0) - (list.tempLimitIncrement || 0); + var upperBound = effectiveLimit ? Math.min(list.offset + effectiveLimit, currentCount) : currentCount; var fieldNames = list.getFieldNames(); for (var i = list.offset; i < upperBound; i++) { var resId = currentResIDs[i]; -- cgit v1.2.3 From 7287c672f54126781854fea2412e50fbf9702bc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Wed, 14 Mar 2018 12:04:46 +0100 Subject: [FIX] web: x2m: properly reset limit/offset to initial value When we discard an element, we want to make sure that the new state is not corrupted by previous user operations. In our case, we possibly had a limit and an offset values modified by the user. This could lead to unpleasant situations, with incorrect data displayed on the form view. Note that this actually fixes a new bug introduced by commit https://github.com/odoo/odoo/commit/e7fab234201e357da52c3576ad2e8fc9ceee9359 (this is the commit that introduces the tempLimitIncrement attribute) --- addons/web/static/src/js/views/basic/basic_model.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'addons/web/static/src/js/views/basic') 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 f081d0a6caa..949eb68cefc 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -359,6 +359,11 @@ var BasicModel = AbstractModel.extend({ elem._changes = null; elem._isDirty = false; } + elem.offset = 0; + if (elem.tempLimitIncrement) { + elem.limit -= elem.tempLimitIncrement; + delete elem.tempLimitIncrement; + } }); }, /** -- cgit v1.2.3 From 61216f116ac5c6e144c693b15408ad13db9f7ed4 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Wed, 14 Mar 2018 14:36:57 +0100 Subject: [FIX] web: add many records in m2m list Have a model with a m2m (field A) this m2m has also a m2m (and displayed as m2m tags in the view) (field AA) Have a domain on field A, to trigger the search view selection Click on add an item Select everything in the modal, making sure that there is more than 40 records Click on Select Before this commit: There was a traceback indicating the local data did not contain records >= 40 This was because the internal data repository was constrained by a limit After this commit: We adapt the limit of the local data repository and there is not traceback OPW 1823400 --- addons/web/static/src/js/views/basic/basic_model.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'addons/web/static/src/js/views/basic') 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 949eb68cefc..e60e3f15a03 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1646,6 +1646,12 @@ var BasicModel = AbstractModel.extend({ // handle multiple add: command[2] may be a dict of values (1 // record added) or an array of dict of values var data = _.isArray(command.ids) ? command.ids : [command.ids]; + + // Ensure the local data repository (list) boundaries can handle incoming records (data) + if (data.length + list.res_ids.length > list.limit) { + list.limit = data.length + list.res_ids.length; + } + var list_records = {}; _.each(data, function (d) { rec = self._makeDataPoint({ -- cgit v1.2.3