Use equality operators when stringify in domain clause with singleton

Closes #13557
This commit is contained in:
Cédric Krier
2024-10-02 17:02:55 +02:00
parent f2e064272f
commit 8edd9f79f8
4 changed files with 26 additions and 6 deletions
+11 -3
View File
@@ -1298,10 +1298,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
@@ -2318,7 +2318,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
@@ -647,10 +647,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%'),