From 50bf8309f88fb6c8d8e27b14d40450e92e5a4e4e Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 16 Jan 2020 14:59:05 +0000 Subject: [FIX] web,*: fix race condition with m2o quick create *sale,sale_product_configurator Let's assume a form view containing a many2one with an onchange that updates the value of a one2many. Do a quick create in the many2one. While the name_create request is pending, add a row to the one2many but do not leave it. When the name_create returns, and the onchange has been performed, the one2many is reset, and the row is no longer in edition (worse, it could be invalid, i.e. in a state that the user could not have reached in a normal situation). This commit fixes this issue by considering the whole [name_create + onchange] operation as one. This operation is executed in the mutex of the model, so the other request (adding a row to the one2many) is delayed until the many2one value has been correctly set. This fixes an issue with the sale and rental tours (on sale_order), that had been deactivated for a while. --- addons/web/static/src/js/fields/relational_fields.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'addons/web/static/src/js/fields') diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index c1f116784fa..deff2fbebcf 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -489,23 +489,12 @@ var FieldMany2One = AbstractField.extend({ dialog.on('closed', self, createDone); }; if (self.nodeOptions.quick_create) { - var nameCreateDef = self._rpc({ - model: self.field.relation, - method: 'name_create', - args: [name], - context: self.record.getContext(self.recordParams), - }).guardedCatch(function (reason) { + const prom = self.reinitialize({id: false, display_name: name}); + prom.guardedCatch(reason => { reason.event.preventDefault(); slowCreate(); }); - self.dp.add(nameCreateDef) - .then(function (result) { - if (self.mode === "edit") { - self.reinitialize({id: result[0], display_name: result[1]}); - } - createDone(); - }) - .guardedCatch(reject); + self.dp.add(prom).then(createDone).guardedCatch(reject); } else { slowCreate(); } -- cgit v1.2.3