[FIX] fields: in to_column(), returning self.column is generally not correct
[odoo/odoo.git] / openerp / addons / test_inherit / models.py
1 # -*- coding: utf-8 -*-
2 from openerp import models, fields, api, osv
3
4 # We just create a new model
5 class mother(models.Model):
6     _name = 'test.inherit.mother'
7
8     _columns = {
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'),
12     }
13
14     surname = fields.Char(compute='_compute_surname')
15
16     @api.one
17     @api.depends('name')
18     def _compute_surname(self):
19         self.surname = self.name or ''
20
21 # We want to inherits from the parent model and we add some fields
22 # in the child object
23 class daughter(models.Model):
24     _name = 'test.inherit.daughter'
25     _inherits = {'test.inherit.mother': 'template_id'}
26
27     template_id = fields.Many2one('test.inherit.mother', 'Template',
28                                   required=True, ondelete='cascade')
29     field_in_daughter = fields.Char('Field1')
30
31
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'
37
38     field_in_mother = fields.Char()
39
40     # extend the name field by adding a default value
41     name = fields.Char(default='Unknown')
42
43     # extend the selection of the state field
44     state = fields.Selection(selection_add=[('c', 'C')])
45
46     # override the computed field, and extend its dependencies
47     @api.one
48     @api.depends('field_in_mother')
49     def _compute_surname(self):
50         if self.field_in_mother:
51             self.surname = self.field_in_mother
52         else:
53             super(mother, self)._compute_surname()
54
55
56 class mother(models.Model):
57     _inherit = 'test.inherit.mother'
58
59     # extend again the selection of the state field
60     state = fields.Selection(selection_add=[('d', 'D')])
61
62
63 class daughter(models.Model):
64     _inherit = 'test.inherit.daughter'
65
66     # simply redeclare the field without adding any option
67     template_id = fields.Many2one()
68
69 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: