diff --git a/sao/src/view/form.js b/sao/src/view/form.js index 7c113038b0..8620ede908 100644 --- a/sao/src/view/form.js +++ b/sao/src/view/form.js @@ -3618,6 +3618,10 @@ function eval_pyson(value){ var context = this.field.get_search_context(this.record); domain = [domain, this.record.expr_eval(this.attributes.add_remove)]; + let existing_ids = this.field.get_eval(this.record); + if (existing_ids.length) { + domain = [domain, ['id', 'not in', existing_ids]]; + } var removed_ids = this.field.get_removed_ids(this.record); domain = ['OR', domain, ['id', 'in', removed_ids]]; var text = this.wid_text.val(); @@ -3909,6 +3913,10 @@ function eval_pyson(value){ var domain = this.field.get_domain(this.record); domain = [domain, this.record.expr_eval(this.attributes.add_remove)]; + let existing_ids = this.field.get_eval(this.record); + if (existing_ids.length) { + domain = [domain, ['id', 'not in', existing_ids]]; + } var removed_ids = this.field.get_removed_ids(this.record); domain = ['OR', domain, ['id', 'in', removed_ids]]; return Sao.common.update_completion( @@ -4169,6 +4177,10 @@ function eval_pyson(value){ if (!jQuery.isEmptyObject(add_remove)) { domain = [domain, add_remove]; } + let existing_ids = this.field.get_eval(this.record); + if (existing_ids.length) { + domain = [domain, ['id', 'not in', existing_ids]]; + } var context = this.field.get_search_context(this.record); var order = this.field.get_search_order(this.record); var value = this.entry.val(); @@ -4327,6 +4339,10 @@ function eval_pyson(value){ if (!jQuery.isEmptyObject(add_remove)) { domain = [domain, add_remove]; } + let existing_ids = this.field.get_eval(this.record); + if (existing_ids.length) { + domain = [domain, ['id', 'not in', existing_ids]]; + } return Sao.common.update_completion( this.entry, this.record, this.field, model, domain); }, diff --git a/tryton/tryton/gui/window/view_form/view/form_gtk/many2many.py b/tryton/tryton/gui/window/view_form/view/form_gtk/many2many.py index b76a0386e0..8cdfd10a38 100644 --- a/tryton/tryton/gui/window/view_form/view/form_gtk/many2many.py +++ b/tryton/tryton/gui/window/view_form/view/form_gtk/many2many.py @@ -177,6 +177,9 @@ class Many2Many(Widget): add_remove = self.record.expr_eval(self.attrs.get('add_remove')) if add_remove: domain = [domain, add_remove] + existing_ids = self.field.get_eval(self.record) + if existing_ids: + domain = [domain, ('id', 'not in', existing_ids)] context = self.field.get_search_context(self.record) order = self.field.get_search_order(self.record) value = self.wid_text.get_text() @@ -369,6 +372,9 @@ class Many2Many(Widget): add_remove = self.record.expr_eval(self.attrs.get('add_remove')) if add_remove: domain = [domain, add_remove] + existing_ids = self.field.get_eval(self.record) + if existing_ids: + domain = [domain, ('id', 'not in', existing_ids)] update_completion( self.wid_text, self.record, self.field, model, domain) diff --git a/tryton/tryton/gui/window/view_form/view/form_gtk/one2many.py b/tryton/tryton/gui/window/view_form/view/form_gtk/one2many.py index fb5ed79f46..3c299c3fd3 100644 --- a/tryton/tryton/gui/window/view_form/view/form_gtk/one2many.py +++ b/tryton/tryton/gui/window/view_form/view/form_gtk/one2many.py @@ -506,6 +506,9 @@ class One2Many(Widget): domain = self.field.domain_get(self.record) context = self.field.get_search_context(self.record) domain = [domain, self.record.expr_eval(self.attrs.get('add_remove'))] + existing_ids = self.field.get_eval(self.record) + if existing_ids: + domain = [domain, ('id', 'not in', existing_ids)] removed_ids = self.field.get_removed_ids(self.record) domain = ['OR', domain, ('id', 'in', removed_ids)] text = self.wid_text.get_text() @@ -612,6 +615,9 @@ class One2Many(Widget): model = self.attrs['relation'] domain = self.field.domain_get(self.record) domain = [domain, self.record.expr_eval(self.attrs.get('add_remove'))] + existing_ids = self.field.get_eval(self.record) + if existing_ids: + domain = [domain, ('id', 'not in', existing_ids)] removed_ids = self.field.get_removed_ids(self.record) domain = ['OR', domain, ('id', 'in', removed_ids)] update_completion(self.wid_text, self.record, self.field, model,