From 9de486eef515145e64cb20fe97d97e7ef6926b81 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 6 May 2015 12:00:13 +0200 Subject: [PATCH] [FIX] web: x2many field: when a record is create (with wizard) the starting_ids must be empty because if they are a onchange, the field recieve again the create commands (duplicate lines). Add destroy method to release the view event garbage --- .../static/src/js/views/form_relational_widgets.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 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 a6ffcd3d058..81752617940 100644 --- a/addons/web/static/src/js/views/form_relational_widgets.js +++ b/addons/web/static/src/js/views/form_relational_widgets.js @@ -513,9 +513,7 @@ var AbstractManyField = common.AbstractField.extend({ this.set('value', []); this.starting_ids = []; this.has_not_committed_changes = false; - this.view.on("load_record", this, function () { - self.starting_ids = self.get('value').slice(); - }); + this.view.on("load_record", this, this._on_load_record); this.dataset.on('dataset_changed', this, function() { self.has_not_committed_changes = true; // the editable lists change the dataset without call AbstractManyField methods @@ -529,6 +527,10 @@ var AbstractManyField = common.AbstractField.extend({ }); }, + _on_load_record: function (record) { + this.starting_ids = record.id ? record[this.name].slice() : []; + }, + set_value: function(ids) { ids = (ids || []).slice(); if (_.find(ids, function(id) { return typeof(id) === "string"; } )) { @@ -723,6 +725,11 @@ var AbstractManyField = common.AbstractField.extend({ is_false: function() { return _(this.get('value')).isEmpty(); }, + + destroy: function () { + this.view.off("load_record", this, this._on_load_record); + this._super(); + } });