From 3136fc1643996f319faf500e303f586d18908010 Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Wed, 13 Sep 2017 14:45:55 +0200 Subject: [FIX] web: reuse datapoint with onchange one one2many Since the rev. https://github.com/odoo/odoo/commit/2728fe1ec1ac7e99819d0f30f29a1814b00c82a4 the onchange create command (0) send the virtual id as second argument. This argument is sent back from the server and can then be used by the client. As the client knows the virtual id, it can easily reuse the datapoint created for this record and thus avoid creating a new one. Creating a new datapoint can potentially lead to problems if the record has for example specialData, that won't be kept. --- addons/web/static/src/js/views/basic/basic_model.js | 18 +++++++++++++++--- 1 file changed, 15 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 5b6eb35b4ac..965237e1df1 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1307,13 +1307,25 @@ var BasicModel = AbstractModel.extend({ record._changes[name] = list.id; var shouldLoad = false; list._changes = list._changes || []; + + // save it in case of a [5] which will remove the _changes + var oldChanges = list._changes; _.each(val, function (command) { - var rec; + var rec, recID; if (command[0] === 0 || command[0] === 1) { // CREATE or UPDATE + if (command[0] === 0 && command[1]) { + // updating an existing (virtual) record + var previousChange = _.find(oldChanges, function (operation) { + var child = self.localData[operation.id]; + return child && (child.res_id === command[1]); + }); + recID = previousChange && previousChange.id; + rec = self.localData[recID]; + } if (command[0] === 1 && command[1]) { // updating an existing record - var recID = _.find(list.data, function (childID) { + recID = _.find(list.data, function (childID) { var child = self.localData[childID]; return child.res_id === command[1]; }); @@ -1327,7 +1339,7 @@ var BasicModel = AbstractModel.extend({ modelName: list.model, parentID: list.id, viewType: list.viewType, - ref: command[1], + ref: command[1], }; if (command[0] === 1) { params.res_id = command[1]; -- cgit v1.2.3 From a8bc2a8bf8211085e1553e720d12d110b234a499 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 20 Sep 2017 14:45:23 +0200 Subject: [FIX] web: several minor issues with editable list - correctly update the pager when a record is added or removed - destroy the widgets of the removed row when the user clicks on 'Cancel' when creating a new record - ensure that the list always contains 4 rows (before this rev., in list views with less than 4 records, if the user created a new record, then clicked on 'Discard', there were only 3 rows left - properly destroy field widgets when removed from the DOM Note that the change of parent.parentID to parent.static is not a bug fix, but it's better to use the key that indicates the type of list element, instead of implying it from other attributes. --- addons/web/static/src/js/views/basic/basic_model.js | 3 ++- 1 file changed, 2 insertions(+), 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 965237e1df1..276fd4df82b 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -769,7 +769,7 @@ var BasicModel = AbstractModel.extend({ removeLine: function (elementID) { var record = this.localData[elementID]; var parent = this.localData[record.parentID]; - if (parent.parentID) { + if (parent.static) { // x2Many case: the new record has been stored in _changes, as a // command so we remove the command(s) related to that record parent._changes = _.filter(parent._changes, function (change) { @@ -778,6 +778,7 @@ var BasicModel = AbstractModel.extend({ } else { // main list view case: the new record is in data parent.data = _.without(parent.data, elementID); + parent.count--; } }, /** -- cgit v1.2.3