-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request odoo#5439 from guewen/test-inherits-3-levels
Reload fields of parent inherits, fixes odoo#5398
- Loading branch information
Showing
8 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import test_inherits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- 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') | ||
|
||
def test_write_3_levels_inherits(self): | ||
""" Check that we can create an inherits on 3 levels """ | ||
pallet = self.env.ref('test_inherits.pallet_a') | ||
pallet.write({'name': 'C'}) | ||
self.assertEqual(pallet.name, 'C') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters