changeset b9ed8d94a300 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=b9ed8d94a300
description:
        Remove extra operator when simplifying nested domains

        issue11406
        review390621002
diffstat:

 trytond/tests/test_tools.py       |  5 +++++
 trytond/tools/domain_inversion.py |  9 +++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diffs (35 lines):

diff -r 0cd242b9bfc4 -r b9ed8d94a300 trytond/tests/test_tools.py
--- a/trytond/tests/test_tools.py       Tue Apr 12 13:09:01 2022 +0200
+++ b/trytond/tests/test_tools.py       Thu Apr 14 10:21:54 2022 +0200
@@ -570,6 +570,11 @@
         self.assertEqual(
             simplify(domain), ['OR', ['x', '=', 3], ['y', '=', 5]])
 
+        domain = ['OR', ('x', '=', 1), ['OR', ('x', '=', 2), ('x', '=', 3)]]
+        self.assertEqual(
+            simplify(domain),
+            ['OR', ('x', '=', 1), ('x', '=', 2), ('x', '=', 3)])
+
         domain = [['x', '=', 3], ['OR']]
         self.assertEqual(simplify(domain), [['x', '=', 3]])
 
diff -r 0cd242b9bfc4 -r b9ed8d94a300 trytond/tools/domain_inversion.py
--- a/trytond/tools/domain_inversion.py Tue Apr 12 13:09:01 2022 +0200
+++ b/trytond/tools/domain_inversion.py Thu Apr 14 10:21:54 2022 +0200
@@ -307,9 +307,14 @@
         domain_op = bool_operator(domain)
         for branch in domain:
             simplified_branch = simplify_nested(branch)
-            if (bool_operator(branch) == domain_op
+            if (bool_operator(simplified_branch) == domain_op
                     or len(simplified_branch) == 1):
-                simplified.extend(simplified_branch)
+                if (simplified
+                        and simplified_branch
+                        and simplified_branch[0] in ['AND', 'OR']):
+                    simplified.extend(simplified_branch[1:])
+                else:
+                    simplified.extend(simplified_branch)
             else:
                 simplified.append(simplified_branch)
         return simplified

Reply via email to