1 # -*- coding: utf-8 -*-
2 from openerp import models, fields, api, osv
4 # We just create a new model
5 class mother(models.Model):
6 _name = 'test.inherit.mother'
9 # check interoperability of field inheritance with old-style fields
10 'name': osv.fields.char('Name', required=True),
11 'state': osv.fields.selection([('a', 'A'), ('b', 'B')], string='State'),
14 surname = fields.Char(compute='_compute_surname')
18 def _compute_surname(self):
19 self.surname = self.name or ''
21 # We want to inherits from the parent model and we add some fields
23 class daughter(models.Model):
24 _name = 'test.inherit.daughter'
25 _inherits = {'test.inherit.mother': 'template_id'}
27 template_id = fields.Many2one('test.inherit.mother', 'Template',
28 required=True, ondelete='cascade')
29 field_in_daughter = fields.Char('Field1')
32 # We add a new field in the parent object. Because of a recent refactoring,
33 # this feature was broken.
34 # This test and these models try to show the bug and fix it.
35 class mother(models.Model):
36 _inherit = 'test.inherit.mother'
38 field_in_mother = fields.Char()
40 # extend the name field by adding a default value
41 name = fields.Char(default='Unknown')
43 # extend the selection of the state field
44 state = fields.Selection(selection_add=[('c', 'C')])
46 # override the computed field, and extend its dependencies
48 @api.depends('field_in_mother')
49 def _compute_surname(self):
50 if self.field_in_mother:
51 self.surname = self.field_in_mother
53 super(mother, self)._compute_surname()
56 class mother(models.Model):
57 _inherit = 'test.inherit.mother'
59 # extend again the selection of the state field
60 state = fields.Selection(selection_add=[('d', 'D')])
63 class daughter(models.Model):
64 _inherit = 'test.inherit.daughter'
66 # simply redeclare the field without adding any option
67 template_id = fields.Many2one()
69 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: