1 # -*- coding: utf-8 -*-
2 from openerp import models, fields, api
4 # We just create a new model
5 class mother(models.Model):
6 _name = 'test.inherit.mother'
8 name = fields.Char('Name', required=True)
9 surname = fields.Char(compute='_compute_surname')
10 state = fields.Selection([('a', 'A'), ('b', 'B')])
14 def _compute_surname(self):
15 self.surname = self.name or ''
17 # We want to inherits from the parent model and we add some fields
19 class daughter(models.Model):
20 _name = 'test.inherit.daughter'
21 _inherits = {'test.inherit.mother': 'template_id'}
23 template_id = fields.Many2one('test.inherit.mother', 'Template',
24 required=True, ondelete='cascade')
25 field_in_daughter = fields.Char('Field1')
28 # We add a new field in the parent object. Because of a recent refactoring,
29 # this feature was broken.
30 # This test and these models try to show the bug and fix it.
31 class mother(models.Model):
32 _inherit = 'test.inherit.mother'
34 field_in_mother = fields.Char()
36 # extend the name field by adding a default value
37 name = fields.Char(default='Unknown')
39 # extend the selection of the state field
40 state = fields.Selection(selection_add=[('c', 'C')])
42 # override the computed field, and extend its dependencies
44 @api.depends('field_in_mother')
45 def _compute_surname(self):
46 if self.field_in_mother:
47 self.surname = self.field_in_mother
49 super(mother, self)._compute_surname()
52 class mother(models.Model):
53 _inherit = 'test.inherit.mother'
55 # extend again the selection of the state field
56 state = fields.Selection(selection_add=[('d', 'D')])
59 class daughter(models.Model):
60 _inherit = 'test.inherit.daughter'
62 # simply redeclare the field without adding any option
63 template_id = fields.Many2one()
65 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: