Use equality operators when stringify in domain clause with singleton

Closes #13557
(grafted from 075696a648468748ed3d9bba7d1bba7553ab21cc)

--HG--
branch : 6.0
This commit is contained in:
Cédric Krier committed 2024-10-02 17:02:55 +02:00
1 parent 4c3cf891e9
commit 075c60bc62
4 files changed
+26 -6

No files matched your search

+11 -3
View File
@@ -1245,10 +1245,18 @@
.replace('not', '!').trim();
}
if (operator.endsWith('in')) {
if (operator == 'not in') {
operator = '!';
if (value instanceof Array && value.length == 1) {
if (operator == 'not in') {
operator = '!=';
} else {
operator = '=';
}
} else {
operator = '';
if (operator == 'not in') {
operator = '!';
} else {
operator = '';
}
}
}
var formatted_value = this.format_value(field, value, target);
+2
View File
@@ -2192,7 +2192,9 @@
[[['name', 'ilike', 'Doe\\%']], 'Name: =Doe%'],
[[['name', 'not ilike', '%Doe%']], 'Name: !Doe'],
[[['name', 'in', ['John', 'Jane']]], 'Name: John;Jane'],
[[['name', 'in', ['John']]], 'Name: =John'],
[[['name', 'not in', ['John', 'Jane']]], 'Name: !John;Jane'],
[[['name', 'not in', ['John']]], 'Name: !=John'],
[[
['name', 'ilike', '%Doe%'],
['name', 'ilike', '%Jane%']
+9 -3
View File
@@ -645,10 +645,16 @@ class DomainParser(object):
operator = operator.rstrip(def_operator
).replace('not', '!').strip()
if operator.endswith('in'):
if operator == 'not in':
operator = '!'
if isinstance(value, (list, tuple)) and len(value) == 1:
if operator == 'not in':
operator = '!='
else:
operator = '='
else:
operator = ''
if operator == 'not in':
operator = '!'
else:
operator = ''
formatted_value = format_value(field, value, target, self.context)
if (operator in OPERATORS
and field['type'] in ('char', 'text', 'selection')
@@ -681,9 +681,13 @@ class DomainParserTestCase(TestCase):
dom.string([('name', 'not ilike', '%Doe%')]), 'Name: !Doe')
self.assertEqual(
dom.string([('name', 'in', ['John', 'Jane'])]), 'Name: John;Jane')
self.assertEqual(
dom.string([('name', 'in', ['John'])]), 'Name: =John')
self.assertEqual(
dom.string([('name', 'not in', ['John', 'Jane'])]),
'Name: !John;Jane')
self.assertEqual(
dom.string([('name', 'not in', ['John'])]), 'Name: !=John')
self.assertEqual(
dom.string([
('name', 'ilike', '%Doe%'),