2014-07-06 14:44:26 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from openerp.tests import common
|
|
|
|
|
|
|
|
class test_inherits(common.TransactionCase):
|
|
|
|
|
|
|
|
def test_access_from_child_to_parent_model(self):
|
|
|
|
""" check whether added field in model is accessible from children models (_inherits) """
|
|
|
|
# This test checks if the new added column of a parent model
|
|
|
|
# is accessible from the child model. This test has been written
|
|
|
|
# to verify the purpose of the inheritance computing of the class
|
|
|
|
# in the openerp.osv.orm._build_model.
|
[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
|
|
|
mother = self.env['test.inherit.mother']
|
|
|
|
daugther = self.env['test.inherit.daugther']
|
2014-07-06 14:44:26 +00:00
|
|
|
|
|
|
|
self.assertIn('field_in_mother', mother._fields)
|
|
|
|
self.assertIn('field_in_mother', daugther._fields)
|
|
|
|
|
|
|
|
def test_field_extension(self):
|
|
|
|
""" check the extension of a field in an inherited model """
|
[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
|
|
|
mother = self.env['test.inherit.mother']
|
2014-07-06 14:44:26 +00:00
|
|
|
field = mother._fields['name']
|
|
|
|
|
|
|
|
# the field should inherit required=True, and have a default value
|
|
|
|
self.assertTrue(field.required)
|
|
|
|
self.assertEqual(field.default, 'Unknown')
|
|
|
|
|
|
|
|
def test_depends_extension(self):
|
|
|
|
""" check that @depends on overridden compute methods extends dependencies """
|
[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
|
|
|
mother = self.env['test.inherit.mother']
|
2014-07-06 14:44:26 +00:00
|
|
|
field = mother._fields['surname']
|
|
|
|
|
|
|
|
# the field dependencies are added
|
|
|
|
self.assertItemsEqual(field.depends, ['name', 'field_in_mother'])
|
|
|
|
|
[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
|
|
|
def test_selection_extension(self):
|
|
|
|
""" check that attribute selection_add=... extends selection on fields. """
|
|
|
|
mother = self.env['test.inherit.mother']
|
|
|
|
field = mother._fields['state']
|
|
|
|
|
|
|
|
# the extra values are added
|
|
|
|
self.assertEqual(field.selection, [('a', 'A'), ('b', 'B'), ('c', 'C'), ('d', 'D')])
|
|
|
|
|
2014-07-06 14:44:26 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|