2014-07-06 14:44:26 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-09-16 12:34:56 +00:00
|
|
|
from openerp import models, fields, api, osv
|
2014-07-06 14:44:26 +00:00
|
|
|
|
|
|
|
# We just create a new model
|
|
|
|
class mother(models.Model):
|
|
|
|
_name = 'test.inherit.mother'
|
|
|
|
|
2014-09-16 12:34:56 +00:00
|
|
|
_columns = {
|
|
|
|
# check interoperability of field inheritance with old-style fields
|
|
|
|
'name': osv.fields.char('Name', required=True),
|
|
|
|
}
|
|
|
|
|
2014-07-06 14:44:26 +00:00
|
|
|
surname = fields.Char(compute='_compute_surname')
|
[IMP] fields: add mechanism to extend a selection field
If a selection field is defined by a list as selection, such as:
state = fields.Selection([('a', 'A'), ('b', 'B')])
one can extend it by inheritance by redefining the field, as:
state = fields.Selection(selection_add=[('c', 'C')])
The result is that the selection field will have the list
[('a', 'A'), ('b', 'B'), ('c', 'C')] as selection.
2014-07-10 20:04:03 +00:00
|
|
|
state = fields.Selection([('a', 'A'), ('b', 'B')])
|
2014-07-06 14:44:26 +00:00
|
|
|
|
|
|
|
@api.one
|
|
|
|
@api.depends('name')
|
|
|
|
def _compute_surname(self):
|
|
|
|
self.surname = self.name or ''
|
|
|
|
|
|
|
|
# We want to inherits from the parent model and we add some fields
|
|
|
|
# in the child object
|
|
|
|
class daughter(models.Model):
|
2014-08-22 08:01:41 +00:00
|
|
|
_name = 'test.inherit.daughter'
|
2014-07-06 14:44:26 +00:00
|
|
|
_inherits = {'test.inherit.mother': 'template_id'}
|
|
|
|
|
|
|
|
template_id = fields.Many2one('test.inherit.mother', 'Template',
|
|
|
|
required=True, ondelete='cascade')
|
|
|
|
field_in_daughter = fields.Char('Field1')
|
|
|
|
|
|
|
|
|
|
|
|
# We add a new field in the parent object. Because of a recent refactoring,
|
|
|
|
# this feature was broken.
|
|
|
|
# This test and these models try to show the bug and fix it.
|
|
|
|
class mother(models.Model):
|
|
|
|
_inherit = 'test.inherit.mother'
|
|
|
|
|
|
|
|
field_in_mother = fields.Char()
|
|
|
|
|
|
|
|
# extend the name field by adding a default value
|
|
|
|
name = fields.Char(default='Unknown')
|
|
|
|
|
[IMP] fields: add mechanism to extend a selection field
If a selection field is defined by a list as selection, such as:
state = fields.Selection([('a', 'A'), ('b', 'B')])
one can extend it by inheritance by redefining the field, as:
state = fields.Selection(selection_add=[('c', 'C')])
The result is that the selection field will have the list
[('a', 'A'), ('b', 'B'), ('c', 'C')] as selection.
2014-07-10 20:04:03 +00:00
|
|
|
# extend the selection of the state field
|
|
|
|
state = fields.Selection(selection_add=[('c', 'C')])
|
|
|
|
|
2014-07-06 14:44:26 +00:00
|
|
|
# override the computed field, and extend its dependencies
|
|
|
|
@api.one
|
|
|
|
@api.depends('field_in_mother')
|
|
|
|
def _compute_surname(self):
|
|
|
|
if self.field_in_mother:
|
|
|
|
self.surname = self.field_in_mother
|
|
|
|
else:
|
|
|
|
super(mother, self)._compute_surname()
|
|
|
|
|
[IMP] fields: add mechanism to extend a selection field
If a selection field is defined by a list as selection, such as:
state = fields.Selection([('a', 'A'), ('b', 'B')])
one can extend it by inheritance by redefining the field, as:
state = fields.Selection(selection_add=[('c', 'C')])
The result is that the selection field will have the list
[('a', 'A'), ('b', 'B'), ('c', 'C')] as selection.
2014-07-10 20:04:03 +00:00
|
|
|
|
|
|
|
class mother(models.Model):
|
|
|
|
_inherit = 'test.inherit.mother'
|
|
|
|
|
|
|
|
# extend again the selection of the state field
|
|
|
|
state = fields.Selection(selection_add=[('d', 'D')])
|
|
|
|
|
2014-08-22 08:01:41 +00:00
|
|
|
|
|
|
|
class daughter(models.Model):
|
|
|
|
_inherit = 'test.inherit.daughter'
|
|
|
|
|
|
|
|
# simply redeclare the field without adding any option
|
|
|
|
template_id = fields.Many2one()
|
|
|
|
|
2014-07-06 14:44:26 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|