[FIX] core: filtered_domain with operators 'like' and 'ilike'

Make the method work when the value to test is `False`.

closes odoo/odoo#58064

X-original-commit: 6fb19219d333dc324603bcb2a937e977eecb037e
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
Raphael Collet
2020-09-18 16:20:05 +00:00
parent b192d8d23f
commit 0e6a8b5faf
2 changed files with 20 additions and 2 deletions
@@ -747,6 +747,20 @@ class TestFields(TransactionCaseWithUserDemo):
})
check(1.0)
def test_20_like(self):
""" test filtered_domain() on char fields. """
record = self.env['test_new_api.multi.tag'].create({'name': 'Foo'})
self.assertTrue(record.filtered_domain([('name', 'like', 'F')]))
self.assertTrue(record.filtered_domain([('name', 'ilike', 'f')]))
record.name = 'Bar'
self.assertFalse(record.filtered_domain([('name', 'like', 'F')]))
self.assertFalse(record.filtered_domain([('name', 'ilike', 'f')]))
record.name = False
self.assertFalse(record.filtered_domain([('name', 'like', 'F')]))
self.assertFalse(record.filtered_domain([('name', 'ilike', 'f')]))
def test_21_date(self):
""" test date fields """
record = self.env['test_new_api.mixed'].create({})
+6 -2
View File
@@ -5273,20 +5273,24 @@ Fields:
elif comparator == 'not in':
ok = all(map(lambda x: x not in data, value))
elif comparator == 'not ilike':
data = [(x or "") for x in data]
ok = all(map(lambda x: value.lower() not in x.lower(), data))
elif comparator == 'ilike':
data = [x.lower() for x in data]
data = [(x or "").lower() for x in data]
ok = bool(fnmatch.filter(data, '*'+(value_esc or '').lower()+'*'))
elif comparator == 'not like':
data = [(x or "") for x in data]
ok = all(map(lambda x: value not in x, data))
elif comparator == 'like':
data = [(x or "") for x in data]
ok = bool(fnmatch.filter(data, value and '*'+value_esc+'*'))
elif comparator == '=?':
ok = (value in data) or not value
elif comparator in ('=like'):
data = [(x or "") for x in data]
ok = bool(fnmatch.filter(data, value_esc))
elif comparator in ('=ilike'):
data = [x.lower() for x in data]
data = [(x or "").lower() for x in data]
ok = bool(fnmatch.filter(data, value and value_esc.lower()))
else:
raise ValueError