Add a failing test to reproduce #5398

This commit is contained in:
Guewen Baconnier 2015-02-20 11:16:45 +01:00
parent f24df6a93c
commit f7b9046c7b
7 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import models

View File

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
{
'name': 'test-inherits',
'version': '0.1',
'category': 'Tests',
'description': """A module to verify the inheritance using _inherits.""",
'author': 'Camptocamp',
'website': 'http://www.camptocamp.com',
'depends': ['base'],
'data': [
'ir.model.access.csv',
'demo_data.xml',
],
'installable': True,
'auto_install': False,
}

View File

@ -0,0 +1,19 @@
<openerp>
<data>
<record id="unit_a" model="test.unit">
<field name="name">Unit A</field>
<field name="state">a</field>
</record>
<record id="box_a" model="test.box">
<field name="unit_id" ref="unit_a"/>
<field name="field_in_box">A</field>
</record>
<record id="pallet_a" model="test.pallet">
<field name="box_id" ref="box_a"/>
<field name="field_in_pallet">A</field>
</record>
</data>
</openerp>

View File

@ -0,0 +1,4 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
access_test_unit,access_test_unit,model_test_unit,,1,1,1,1
access_test_box,access_test_box,model_test_box,,1,1,1,1
access_test_pallet,access_test_pallet,model_test_pallet,,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_test_unit access_test_unit model_test_unit 1 1 1 1
3 access_test_box access_test_box model_test_box 1 1 1 1
4 access_test_pallet access_test_pallet model_test_pallet 1 1 1 1

View File

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
from openerp import models, fields, api, osv
# We just create a new model
class Unit(models.Model):
_name = 'test.unit'
_columns = {
'name': osv.fields.char('Name', required=True),
'state': osv.fields.selection([('a', 'A'), ('b', 'B')],
string='State'),
}
surname = fields.Char(compute='_compute_surname')
@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 Box(models.Model):
_name = 'test.box'
_inherits = {'test.unit': 'unit_id'}
unit_id = fields.Many2one('test.unit', 'Unit', required=True,
ondelete='cascade')
field_in_box = fields.Char('Field1')
# We add a third level of _inherits
class Pallet(models.Model):
_name = 'test.pallet'
_inherits = {'test.box': 'box_id'}
box_id = fields.Many2one('test.box', 'Box', required=True,
ondelete='cascade')
field_in_pallet = fields.Char('Field2')

View File

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import test_inherits

View File

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from openerp.tests import common
class test_inherits(common.TransactionCase):
def test_create_3_levels_inherits(self):
""" Check that we can create an inherits on 3 levels """
pallet = self.env['test.pallet'].create({
'name': 'B',
'field_in_box': 'box',
'field_in_pallet': 'pallet',
})
self.assertTrue(pallet)
self.assertEqual(pallet.name, 'B')
self.assertEqual(pallet.field_in_box, 'box')
self.assertEqual(pallet.field_in_pallet, 'pallet')