From eba1c56f9798681eb94496452fb6aed898e7e18c Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Mon, 8 Dec 2014 15:33:43 +0100 Subject: [PATCH] [FIX] web: ensure one2many field destruction on button cancel The destruction of one2many fields is forced with the event change:effective_readonly This revision add the forced destruction for cancel(discard) button as well Otherwise, one2many fields are not properly destroyed when hitting the button "discard" (from save or discard). This can be problematic for one2many editable list views (such as invoice lines) if you discard while having a mandatory field not filled in the invoice line: You can't recreate an invoice, the one2many editable list is messed up Use case: Create an invoice, create a line, leave the description, required field, empty. Then, discard. Then, click on create. opw-616946 --- addons/web/static/src/js/view_form.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index be16faa309a..ed246e58da6 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3540,16 +3540,18 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ var self = this; self.load_views(); - this.is_loaded.done(function() { - self.on("change:effective_readonly", self, function() { - self.is_loaded = self.is_loaded.then(function() { - self.viewmanager.destroy(); - return $.when(self.load_views()).done(function() { - self.reload_current_view(); - }); + var destroy = function() { + self.is_loaded = self.is_loaded.then(function() { + self.viewmanager.destroy(); + return $.when(self.load_views()).done(function() { + self.reload_current_view(); }); }); + }; + this.is_loaded.done(function() { + self.on("change:effective_readonly", self, destroy); }); + this.view.on("on_button_cancel", self, destroy); this.is_started = true; this.reload_current_view(); },