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
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user