From 9865cc43e63dee31f38cdba2875aa3d926b2b0ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 24 Mar 2018 13:50:47 +0100 Subject: [PATCH] Add test to check that depends on _parent_ contains also the relation Otherwise, the depends decorator will set the relation to None if the record is not in One2Many widget. And the method will not behave the same as if the record was in a One2Many widget. And if it is an on_change call, it will remove the value on the client side. issue7249 review45291002 --- trytond/tests/test_tryton.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/trytond/tests/test_tryton.py b/trytond/tests/test_tryton.py index feaec077e5..9725c8817d 100644 --- a/trytond/tests/test_tryton.py +++ b/trytond/tests/test_tryton.py @@ -315,6 +315,27 @@ class ModuleTestCase(unittest.TestCase): 'Unknown depends %s in button "%s"."%s"' % ( list(depends - set(model._fields)), mname, bname)) + @with_transaction() + def test_depends_parent(self): + "Test depends on _parent_ contains also the parent relation" + for mname, model in Pool().iterobject(): + if not isregisteredby(model, self.module): + continue + for fname, field in model._fields.iteritems(): + for attribute in ['depends', 'on_change', 'on_change_with', + 'selection_change_with', 'autocomplete']: + depends = getattr(field, attribute, []) + for depend in depends: + prefix = [] + for d in depend.split('.'): + if d.startswith('_parent_'): + relation = '.'.join( + prefix + [d[len('_parent_'):]]) + assert relation in depends, ( + 'Missing "%s" in "%s"."%s"."%s"' % ( + relation, mname, fname, attribute)) + prefix.append(d) + @with_transaction() def test_field_methods(self): 'Test field methods'