From cfeb3685f45fb7dfc7dc53a92e3c32fd7b71d50b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 26 Feb 2025 23:51:39 +0100 Subject: [PATCH] Convert empty string to None for match value It is not possible from the clients to force to store None value instead of empty string. Closes #13890 --- trytond/trytond/model/match.py | 2 ++ trytond/trytond/tests/test_model_match.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/trytond/trytond/model/match.py b/trytond/trytond/model/match.py index 4b168828f5..bdbbf00828 100644 --- a/trytond/trytond/model/match.py +++ b/trytond/trytond/model/match.py @@ -11,6 +11,8 @@ class MatchMixin(object): and matching value as value''' for field_name, pattern_value in pattern.items(): value = getattr(self, field_name) + if value == '': + value = None if not match_none and value is None: continue field = self._fields[field_name] diff --git a/trytond/trytond/tests/test_model_match.py b/trytond/trytond/tests/test_model_match.py index 39ce043573..82bf3bc32d 100644 --- a/trytond/trytond/tests/test_model_match.py +++ b/trytond/trytond/tests/test_model_match.py @@ -35,7 +35,9 @@ class ModelMatchMixinTestCase(TestCase): (Model(f=(fields.Char("F"), 'foo')), {'f': 'bar'}, False), (Model(f=(fields.Char("F"), 'foo')), {'f': None}, False), (Model(f=(fields.Char("F"), None)), {'f': 'foo'}, True), + (Model(f=(fields.Char("F"), '')), {'f': 'foo'}, True), (Model(f=(fields.Char("F"), None)), {'f': None}, True), + (Model(f=(fields.Char("F"), '')), {'f': None}, True), ]: with self.subTest(record=record, pattern=pattern): self.assertEqual(record.match(pattern), result) @@ -47,7 +49,9 @@ class ModelMatchMixinTestCase(TestCase): (Model(f=(fields.Char("F"), 'foo')), {'f': 'bar'}, False), (Model(f=(fields.Char("F"), 'foo')), {'f': None}, False), (Model(f=(fields.Char("F"), None)), {'f': 'foo'}, False), + (Model(f=(fields.Char("F"), '')), {'f': 'foo'}, False), (Model(f=(fields.Char("F"), None)), {'f': None}, True), + (Model(f=(fields.Char("F"), '')), {'f': None}, True), ]: with self.subTest(record=record, pattern=pattern): self.assertEqual(