From f9a1241721d1457dd7ddd0eebb1ec0ba4fba3225 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 31 May 2017 08:55:24 +0200 Subject: [FIX] web: editable list: don't create invalid records Clicking multiple times on 'Create' (in main list views) or 'Add an item' (in o2m lists) might create invalid rows (i.e. rows with required fields unset). Creating a new record requires two sequential RPCs: a default_get and an onchange (only if there is an onchange of one of the record's field). When clicking twice to create a new record, that sequence of RPCs is done twice in parallel, after unselecting the current row (i.e. saving it if it is valid). However, in both cases, there is no line to unselect yet (as both operations are done basically simultaneously). When the first onchange returns, a first new record is added to the list. When the second returns, the second one is added and takes the edition, leaving the first one, invalid, in the list. This rev. ensures this doesn't happen by preventing concurrent record creation. --- .../web/static/src/js/fields/relational_fields.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src/js/fields/relational_fields.js') diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index f223fca68a4..a5f9b443ae0 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -914,6 +914,16 @@ var FieldOne2Many = FieldX2Many.extend({ className: 'o_field_one2many', supportedFieldTypes: ['one2many'], + /** + * @override + */ + init: function () { + this._super.apply(this, arguments); + + // boolean used to prevent concurrent record creation + this.creatingRecord = false; + }, + //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- @@ -931,6 +941,7 @@ var FieldOne2Many = FieldX2Many.extend({ var index = self.editable === 'top' ? 0 : self.value.data.length - 1; var newID = self.value.data[index].id; self.renderer.editRecord(newID); + self.creatingRecord = false; } } }); @@ -984,10 +995,13 @@ var FieldOne2Many = FieldX2Many.extend({ ev.stopPropagation(); if (this.editable) { - this._setValue({ - operation: 'CREATE', - position: this.editable, - }); + if (!this.creatingRecord) { + this.creatingRecord = true; + this._setValue({ + operation: 'CREATE', + position: this.editable, + }); + } } else { var self = this; this._openFormDialog({ -- cgit v1.2.3