[FIX] expression: properly handle {TRUE,FALSE}_LEAF

Before this commit, doing expression.OR() with only FALSE_LEAF would
yield [] which is equivalent to TRUE_LEAF and is therefore not correct.

The same happened (to a lesser extent) with expression.AND() within an
expression.OR(), since the former would return a [] which would be
ignored by expression.OR().

See tests for a clearer view of the use cases.

Fixes #30113, #26540

closes odoo/odoo#31202
This commit is contained in:
Adrian Torres
2019-02-20 10:45:28 +00:00
parent c7386de1a2
commit 934c001680
2 changed files with 31 additions and 1 deletions
+30
View File
@@ -612,6 +612,36 @@ class TestExpression(TransactionCase):
not_be = Partner.with_context(lang='fr_FR').search([('country_id', '!=', 'Belgique')])
self.assertNotIn(agrolait, not_be)
def test_proper_combine_unit_leaves(self):
# test that unit leaves (TRUE_LEAF, FALSE_LEAF) are properly handled in specific cases
false = expression.FALSE_DOMAIN
true = expression.TRUE_DOMAIN
normal = [('foo', '=', 'bar')]
# OR with single FALSE_LEAF
expr = expression.OR([false])
self.assertEqual(expr, false)
# OR with multiple FALSE_LEAF
expr = expression.OR([false, false])
self.assertEqual(expr, false)
# OR with FALSE_LEAF and a normal leaf
expr = expression.OR([false, normal])
self.assertEqual(expr, normal)
# OR with AND of single TRUE_LEAF and normal leaf
expr = expression.OR([expression.AND([true]), normal])
self.assertEqual(expr, true)
# AND with single TRUE_LEAF
expr = expression.AND([true])
self.assertEqual(expr, true)
# AND with multiple TRUE_LEAF
expr = expression.AND([true, true])
self.assertEqual(expr, true)
# AND with TRUE_LEAF and normal leaves
expr = expression.AND([true, normal])
self.assertEqual(expr, normal)
# AND with OR with single FALSE_LEAF and normal leaf
expr = expression.AND([expression.OR([false]), normal])
self.assertEqual(expr, false)
class TestAutoJoin(TransactionCase):
+1 -1
View File
@@ -233,7 +233,7 @@ def combine(operator, unit, zero, domains):
result += domain
count += 1
result = [operator] * (count - 1) + result
return result
return result or unit
def AND(domains):