[IMP] test_inherit: add test case, redefine Many2one field in inherited model
authorRaphael Collet <rco@openerp.com>
Fri, 22 Aug 2014 08:01:41 +0000 (10:01 +0200)
committerRaphael Collet <rco@openerp.com>
Fri, 22 Aug 2014 08:01:41 +0000 (10:01 +0200)
openerp/addons/test_inherit/ir.model.access.csv
openerp/addons/test_inherit/models.py
openerp/addons/test_inherit/tests/test_inherit.py

index 79644d6..9118525 100644 (file)
@@ -1,3 +1,3 @@
 "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_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
index f620dfe..e1957ab 100644 (file)
@@ -17,7 +17,7 @@ class mother(models.Model):
 # We want to inherits from the parent model and we add some fields
 # in the child object
 class daughter(models.Model):
-    _name = 'test.inherit.daugther'
+    _name = 'test.inherit.daughter'
     _inherits = {'test.inherit.mother': 'template_id'}
 
     template_id = fields.Many2one('test.inherit.mother', 'Template',
@@ -55,4 +55,11 @@ class mother(models.Model):
     # extend again the selection of the state field
     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:
index 8039e69..bbd6ef0 100644 (file)
@@ -10,20 +10,28 @@ class test_inherits(common.TransactionCase):
         # to verify the purpose of the inheritance computing of the class
         # in the openerp.osv.orm._build_model.
         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', daugther._fields)
 
     def test_field_extension(self):
         """ 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']
         field = mother._fields['name']
-
-        # the field should inherit required=True, and have a default value
         self.assertTrue(field.required)
         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):
         """ check that @depends on overridden compute methods extends dependencies """
         mother = self.env['test.inherit.mother']