changeset ea8dd19e5913 in tryton:default details: https://hg.tryton.org/tryton?cmd=changeset;node=ea8dd19e5913 description: Add domain inversion for reference fields
issue7877 review45831002 diffstat: CHANGELOG | 1 + tryton/common/domain_inversion.py | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diffs (55 lines): diff -r 5fc576fc54a2 -r ea8dd19e5913 CHANGELOG --- a/CHANGELOG Wed Apr 10 10:26:40 2019 +0200 +++ b/CHANGELOG Sun Apr 14 14:18:03 2019 +0200 @@ -1,3 +1,4 @@ +* Add domain inversion for reference fields * Add list-form view * Remove support for Python 3.4 * Replace ColorSelectionDialog by ColorChooserDialog diff -r 5fc576fc54a2 -r ea8dd19e5913 tryton/common/domain_inversion.py --- a/tryton/common/domain_inversion.py Wed Apr 10 10:26:40 2019 +0200 +++ b/tryton/common/domain_inversion.py Sun Apr 14 14:18:03 2019 +0200 @@ -281,12 +281,18 @@ def unique_value(domain): "Return if unique, the field and the value" if (isinstance(domain, list) - and len(domain) == 1 - and '.' not in domain[0][0] - and domain[0][1] == '='): - return True, domain[0][1], domain[0][2] - else: - return False, None, None + and len(domain) == 1): + domain, = domain + name = domain[0] + value = domain[2] + count = 0 + if len(domain) == 4 and name[-3:] == '.id': + count = 1 + model = domain[3] + value = [model, value] + if name.count('.') == count and domain[1] == '=': + return True, domain[1], value + return False, None, None def parse(domain): @@ -586,6 +592,10 @@ assert unique_value(domain)[0] is False domain = [['a.b', '=', 1]] assert unique_value(domain)[0] is False + domain = [['a.id', '=', 1, 'model']] + assert unique_value(domain) == (True, '=', ['model', 1]) + domain = [['a.b.id', '=', 1, 'model']] + assert unique_value(domain) == (False, None, None) def test_evaldomain(): @@ -803,6 +813,7 @@ test_oror_inversion() test_parse() test_simplify() + test_unique_value() test_evaldomain() test_localize() test_prepare_reference_domain()