From b630c199a5d82f00769df30ac75d748d78a76533 Mon Sep 17 00:00:00 2001 From: Denis Ledoux <dle@odoo.com> Date: Wed, 22 Jun 2016 17:58:45 +0200 Subject: [PATCH] [FIX] web: 2many race condition on fast click on Save / Edit For `this.viewmanager.active_view` to be set, the view manager switch mode must be completed, meaning the deferred returned by the function `switch_mode` must be resolved (see `this.active_view = view;` in `view_manager.js`, line 146) In a 2many field, the view manager `switch_mode` deferred is resolved when `is_loaded` of this field is as well resolved. Before this revision, clicking fast on Save then Edit of a vendor bills resulted to a JS error due to a race condition, because `this.viewmanager.active_view` was undefined when the field was not loaded / the view manager switch mode not completed. opw-678097 --- .../src/js/views/form_relational_widgets.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/addons/web/static/src/js/views/form_relational_widgets.js b/addons/web/static/src/js/views/form_relational_widgets.js index 61fd63d9e727..f1c6e0b36b1f 100644 --- a/addons/web/static/src/js/views/form_relational_widgets.js +++ b/addons/web/static/src/js/views/form_relational_widgets.js @@ -1287,13 +1287,15 @@ var FieldOne2Many = FieldX2Many.extend({ }, commit_value: function() { var self = this; - var view = this.viewmanager.active_view; - if(view.type === "list" && view.controller.editable()) { - return this.mutex.def.then(function () { - return view.controller.save_edition(); - }); - } - return this.mutex.def; + return this.is_loaded.then(function() { + var view = self.viewmanager.active_view; + if(view.type === "list" && view.controller.editable()) { + return self.mutex.def.then(function () { + return view.controller.save_edition(); + }); + } + return self.mutex.def; + }); }, }); -- GitLab