From 82b0f2779b54fdc3297e470d7cf1fad0868eec6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 11 Feb 2023 18:07:06 +0100 Subject: [PATCH] Enforce unique value for invisible field Closes #12034 --- sao/CHANGELOG | 2 +- sao/src/model.js | 2 ++ tryton/CHANGELOG | 2 +- tryton/tryton/gui/window/view_form/model/field.py | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sao/CHANGELOG b/sao/CHANGELOG index 9a21dd938f..17b53c88f2 100644 --- a/sao/CHANGELOG +++ b/sao/CHANGELOG @@ -7,7 +7,7 @@ * Use toggle button and label on translate dialog * Support border type of images * Manage domain on id in single value list as unique -* Do not validate domain and enforce uniqueness for empty fields unless they're required +* Do not validate domain nor enforce uniqueness for empty fields unless they're required or invisible * Display the number of selected records on xxx2Many Version 6.6.0 - 2022-10-31 diff --git a/sao/src/model.js b/sao/src/model.js index a2b318a098..b58474bc3c 100644 --- a/sao/src/model.js +++ b/sao/src/model.js @@ -1662,6 +1662,7 @@ var invalid = false; var state_attrs = this.get_state_attrs(record); var is_required = Boolean(parseInt(state_attrs.required, 10)); + var is_invisible = Boolean(parseInt(state_attrs.invisible, 10)); state_attrs.domain_readonly = false; var inversion = new Sao.common.DomainInversion(); var domain = inversion.simplify(this.validation_domains(record, @@ -1688,6 +1689,7 @@ screen_domain)[0]; if (this._is_empty(record) && !is_required && + !is_invisible && !unique_from_screen) { // Do nothing } else if (unique) { diff --git a/tryton/CHANGELOG b/tryton/CHANGELOG index 187892f63b..27d98ac451 100644 --- a/tryton/CHANGELOG +++ b/tryton/CHANGELOG @@ -5,7 +5,7 @@ * Use ``&`` and ``|`` as boolean operator in search widget * Use toggle button and label on translate dialog * Manage domain on id in single value list as unique -* Do not validate domain and enforce uniqueness for empty fields unless they're required +* Do not validate domain nor enforce uniqueness for empty fields unless they're required or invisible * Display the number of selected records on xxx2Many Version 6.6.0 - 2022-10-31 diff --git a/tryton/tryton/gui/window/view_form/model/field.py b/tryton/tryton/gui/window/view_form/model/field.py index d499ae6527..a383def7e3 100644 --- a/tryton/tryton/gui/window/view_form/model/field.py +++ b/tryton/tryton/gui/window/view_form/model/field.py @@ -97,6 +97,7 @@ class Field(object): return True state_attrs = self.get_state_attrs(record) is_required = bool(int(state_attrs.get('required') or 0)) + is_invisible = bool(int(state_attrs.get('invisible') or 0)) invalid = False state_attrs['domain_readonly'] = False domain = simplify(self.validation_domains(record, pre_validate)) @@ -114,6 +115,7 @@ class Field(object): unique_from_screen, _, _ = unique_value(screen_domain) if (self._is_empty(record) and not is_required + and not is_invisible and not unique_from_screen): pass elif unique: