[IMP] test_inherit: add test case, redefine Many2one field in inherited model
This commit is contained in:
parent
5e5c73e7ba
commit
775eaae930
|
@ -1,3 +1,3 @@
|
||||||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
||||||
access_test_inherit_mother,access_test_inherit_mother,model_test_inherit_mother,,1,1,1,1
|
access_test_inherit_mother,access_test_inherit_mother,model_test_inherit_mother,,1,1,1,1
|
||||||
access_test_inherit_daugther,access_test_inherit_daugther,model_test_inherit_daugther,,1,1,1,1
|
access_test_inherit_daughter,access_test_inherit_daughter,model_test_inherit_daughter,,1,1,1,1
|
||||||
|
|
|
|
@ -17,7 +17,7 @@ class mother(models.Model):
|
||||||
# We want to inherits from the parent model and we add some fields
|
# We want to inherits from the parent model and we add some fields
|
||||||
# in the child object
|
# in the child object
|
||||||
class daughter(models.Model):
|
class daughter(models.Model):
|
||||||
_name = 'test.inherit.daugther'
|
_name = 'test.inherit.daughter'
|
||||||
_inherits = {'test.inherit.mother': 'template_id'}
|
_inherits = {'test.inherit.mother': 'template_id'}
|
||||||
|
|
||||||
template_id = fields.Many2one('test.inherit.mother', 'Template',
|
template_id = fields.Many2one('test.inherit.mother', 'Template',
|
||||||
|
@ -55,4 +55,11 @@ class mother(models.Model):
|
||||||
# extend again the selection of the state field
|
# extend again the selection of the state field
|
||||||
state = fields.Selection(selection_add=[('d', 'D')])
|
state = fields.Selection(selection_add=[('d', 'D')])
|
||||||
|
|
||||||
|
|
||||||
|
class daughter(models.Model):
|
||||||
|
_inherit = 'test.inherit.daughter'
|
||||||
|
|
||||||
|
# simply redeclare the field without adding any option
|
||||||
|
template_id = fields.Many2one()
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
|
@ -10,20 +10,28 @@ class test_inherits(common.TransactionCase):
|
||||||
# to verify the purpose of the inheritance computing of the class
|
# to verify the purpose of the inheritance computing of the class
|
||||||
# in the openerp.osv.orm._build_model.
|
# in the openerp.osv.orm._build_model.
|
||||||
mother = self.env['test.inherit.mother']
|
mother = self.env['test.inherit.mother']
|
||||||
daugther = self.env['test.inherit.daugther']
|
daugther = self.env['test.inherit.daughter']
|
||||||
|
|
||||||
self.assertIn('field_in_mother', mother._fields)
|
self.assertIn('field_in_mother', mother._fields)
|
||||||
self.assertIn('field_in_mother', daugther._fields)
|
self.assertIn('field_in_mother', daugther._fields)
|
||||||
|
|
||||||
def test_field_extension(self):
|
def test_field_extension(self):
|
||||||
""" check the extension of a field in an inherited model """
|
""" check the extension of a field in an inherited model """
|
||||||
|
# the field mother.name should inherit required=True, and have a default
|
||||||
|
# value
|
||||||
mother = self.env['test.inherit.mother']
|
mother = self.env['test.inherit.mother']
|
||||||
field = mother._fields['name']
|
field = mother._fields['name']
|
||||||
|
|
||||||
# the field should inherit required=True, and have a default value
|
|
||||||
self.assertTrue(field.required)
|
self.assertTrue(field.required)
|
||||||
self.assertEqual(field.default, 'Unknown')
|
self.assertEqual(field.default, 'Unknown')
|
||||||
|
|
||||||
|
# the field daugther.template_id should inherit
|
||||||
|
# model_name='test.inherit.mother', string='Template', required=True
|
||||||
|
daugther = self.env['test.inherit.daughter']
|
||||||
|
field = daugther._fields['template_id']
|
||||||
|
self.assertEqual(field.comodel_name, 'test.inherit.mother')
|
||||||
|
self.assertEqual(field.string, "Template")
|
||||||
|
self.assertTrue(field.required)
|
||||||
|
|
||||||
def test_depends_extension(self):
|
def test_depends_extension(self):
|
||||||
""" check that @depends on overridden compute methods extends dependencies """
|
""" check that @depends on overridden compute methods extends dependencies """
|
||||||
mother = self.env['test.inherit.mother']
|
mother = self.env['test.inherit.mother']
|
||||||
|
|
Loading…
Reference in New Issue