diff --git a/sao/src/common.js b/sao/src/common.js index 5c88c69472..ea8b696e01 100644 --- a/sao/src/common.js +++ b/sao/src/common.js @@ -2765,18 +2765,18 @@ if ((domain instanceof Array) && (domain.length == 1)) { let [name, operator, value, ...model] = domain[0]; - if (operator == '=' || - (single_value && operator == 'in' && value.length == 1)) { + const count = name.split('.').length - 1; + if ( + (operator == '=' || + (single_value && operator == 'in' && value.length == 1)) && + (!count || + ((count === 1) && model.length && name.endsWith('.id')))) { value = operator == '=' ? value : value[0]; - var count = 0; if (model.length && name.endsWith('.id')) { - count = 1; model = model[0]; value = [model, value]; } - if ((name.split('.').length - 1) == count) { - return [true, name, value]; - } + return [true, name, value]; } } return [false, null, null]; diff --git a/sao/tests/sao.js b/sao/tests/sao.js index 25f85b4fca..7d5c87ae09 100644 --- a/sao/tests/sao.js +++ b/sao/tests/sao.js @@ -2814,6 +2814,7 @@ QUnit.ok(compare(unique_value(domain), [true, 'a.id', ['model', 1]])); domain = [['a.b.id', '=', 1, 'model']]; QUnit.ok(compare(unique_value(domain), [false, null, null])); + QUnit.ok(compare(unique_value(domain, false), [false, null, null])); domain = [['a', 'in', [1]]]; QUnit.ok(compare(unique_value(domain), [true, 'a', 1])); QUnit.ok(compare(unique_value(domain, false), [false, null, null])); @@ -2825,6 +2826,7 @@ QUnit.ok(compare(unique_value(domain), [false, null, null])); domain = [['a.id', 'in', [1], 'model']]; QUnit.ok(compare(unique_value(domain), [true, 'a.id', ['model', 1]])); + QUnit.ok(compare(unique_value(domain, false), [false, null, null])); }); QUnit.test('DomainInversion evaldomain', function() { diff --git a/tryton/tryton/common/domain_inversion.py b/tryton/tryton/common/domain_inversion.py index 02c7232a99..efbf0735c0 100644 --- a/tryton/tryton/common/domain_inversion.py +++ b/tryton/tryton/common/domain_inversion.py @@ -426,16 +426,18 @@ def unique_value(domain, single_value=True): if (isinstance(domain, list) and len(domain) == 1): name, operator, value, *model = domain[0] - if (operator == '=' - or (single_value and operator == 'in' and len(value) == 1)): + count = name.count('.') + if ( + (operator == '=' + or (single_value + and operator == 'in' and len(value) == 1)) + and (not count + or (count == 1 and model and name.endswith('.id')))): value = value if operator == '=' and single_value else value[0] - count = 0 if model and name.endswith('.id'): - count = 1 model = model[0] value = [model, value] - if name.count('.') == count: - return True, name, value + return True, name, value return False, None, None diff --git a/trytond/trytond/tests/test_tools.py b/trytond/trytond/tests/test_tools.py index c2ae439f52..b4d843203f 100644 --- a/trytond/trytond/tests/test_tools.py +++ b/trytond/trytond/tests/test_tools.py @@ -846,6 +846,8 @@ class DomainInversionTestCase(unittest.TestCase): domain = [['a.b.id', '=', 1, 'model']] self.assertEqual(unique_value(domain), (False, None, None)) + self.assertEqual( + unique_value(domain, single_value=False), (False, None, None)) domain = [['a', 'in', [1]]] self.assertEqual(unique_value(domain), (True, 'a', 1)) @@ -863,6 +865,8 @@ class DomainInversionTestCase(unittest.TestCase): domain = [['a.id', 'in', [1], 'model']] self.assertEqual(unique_value(domain), (True, 'a.id', ['model', 1])) + self.assertEqual( + unique_value(domain, single_value=False), (False, None, None)) def test_evaldomain(self): domain = [['x', '>', 5]] diff --git a/trytond/trytond/tools/domain_inversion.py b/trytond/trytond/tools/domain_inversion.py index 46926d0fc5..efbf0735c0 100644 --- a/trytond/trytond/tools/domain_inversion.py +++ b/trytond/trytond/tools/domain_inversion.py @@ -426,16 +426,18 @@ def unique_value(domain, single_value=True): if (isinstance(domain, list) and len(domain) == 1): name, operator, value, *model = domain[0] - if (operator == '=' - or (single_value and operator == 'in' and len(value) == 1)): - value = value if operator == '=' else value[0] - count = 0 + count = name.count('.') + if ( + (operator == '=' + or (single_value + and operator == 'in' and len(value) == 1)) + and (not count + or (count == 1 and model and name.endswith('.id')))): + value = value if operator == '=' and single_value else value[0] if model and name.endswith('.id'): - count = 1 model = model[0] value = [model, value] - if name.count('.') == count: - return True, name, value + return True, name, value return False, None, None