Use equality operators when stringify in domain clause with singleton
Closes #13557
This commit is contained in:
+11
-3
@@ -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);
|
||||
|
||||
@@ -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%']
|
||||
|
||||
@@ -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%'),
|
||||
|
||||
Reference in New Issue
Block a user