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'),
11 'state': osv.fields.selection([('a', 'A'), ('b', 'B')], string='State'),
17 surname = fields.Char(compute='_compute_surname')
21 def _compute_surname(self):
22 self.surname = self.name or ''
24 # We want to inherits from the parent model and we add some fields
26 class daughter(models.Model):
27 _name = 'test.inherit.daughter'
28 _inherits = {'test.inherit.mother': 'template_id'}
30 template_id = fields.Many2one('test.inherit.mother', 'Template',
31 required=True, ondelete='cascade')
32 field_in_daughter = fields.Char('Field1')
35 # We add a new field in the parent object. Because of a recent refactoring,
36 # this feature was broken.
37 # This test and these models try to show the bug and fix it.
38 class mother(models.Model):
39 _inherit = 'test.inherit.mother'
41 field_in_mother = fields.Char()
43 # extend the name field: make it required and change its default value
44 name = fields.Char(required=True, default='Bar')
46 # extend the selection of the state field
47 state = fields.Selection(selection_add=[('c', 'C')])
49 # override the computed field, and extend its dependencies
51 @api.depends('field_in_mother')
52 def _compute_surname(self):
53 if self.field_in_mother:
54 self.surname = self.field_in_mother
56 super(mother, self)._compute_surname()
59 class mother(models.Model):
60 _inherit = 'test.inherit.mother'
62 # extend again the selection of the state field
63 state = fields.Selection(selection_add=[('d', 'D')])
66 class daughter(models.Model):
67 _inherit = 'test.inherit.daughter'
69 # simply redeclare the field without adding any option
70 template_id = fields.Many2one()
72 # change the default value of an inherited field
73 name = fields.Char(default='Baz')
75 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: