[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
This commit is contained in:
Denis Ledoux 2014-12-08 15:33:43 +01:00
parent 284ca73b1c
commit eba1c56f97
1 changed files with 9 additions and 7 deletions

View File

@ -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();
},