Reputation: 157
I have successfully created module and it is working absolutely fine. Now from that module i have inheritated another module for which i need your support for xml genaration. I have given original module .py and xml file along with new module .py file. Please provide me the xml for new module
ORIGINAL module .py file
from osv import osv
from osv import fields
class test_base(osv.osv):
_name='test.base'
_columns={
'name':fields.char('Name'),
'email':fields.char('Email'),
'code':fields.integer('Unique ID'),
'sal':fields.float('Salary'),
'rate':fields.selection(((10,'10'), (20,'20'),(30,'30')),
'Percentage of Deduction'),
'ded':fields.float('Deduction'),
'bdisplay':fields.float('Button Display'),
}
def on_change_ded_cal(self, cr, uid, ids,rate,context=None):
x=rate*2
return {'value':{'ded':x }}
test_base()
original module xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="test_base_form">
<field name="name">test.base.form</field>
<field name="model">test.base</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Test Base">
<field name="name"/>
<field name="email"/>
<field name="code"/>
<field name="sal"/>
<field name="rate" on_change="on_change_ded_cal(rate)"/>
<field name="ded"/>
<field name="bdisplay"/>
</form>
</field>
</record>
<record model="ir.ui.view" id="test_base_tree">
<field name="name">test.base.tree</field>
<field name="model">test.base</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Test Base">
<field name="name"/>
<field name="email"/>
<field name="code"/>
<field name="sal"/>
<field name="ded"/>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_test_seq">
<field name="name">Test Base</field>
<field name="res_model">test.base</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_test_base_main" name="Test Base" action="action_test_seq"/>
<menuitem id="menu_test_base" parent="menu_test_base_main"
name="Test Base1" action="action_test_seq"/>
</data>
</openerp>
New module .py file
from osv import osv
from osv import fields
class my_base(osv.osv):
_name='my.base'
_inherit='test.base'
_columns={
'dept':fields.char('Department'),
}
my_base()
(new field 'dept can be added after 'ded' field also please explain on xml id's)
Upvotes: 0
Views: 3898
Reputation: 5044
Here you have inherited the test.base
model and its functionality to my.base
. So my.base
will be considered as a new model and you have define a new view for your my.base
model. You cannot inherit the view of test.base
. If you are trying to add a new field to the test.base
model, then from your my_base() class
remove the _name attribute or change the name attribute to _name ='test.base'
. Then you can inherit the view of test.base model to add the new field. For example you want to add new field 'dept' to the tree view of test.base, then
<record model="ir.ui.view" id="test_base_tree_inheirt">
<field name="name">test.base.tree</field>
<field name="model">test.base</field>
<field name="type">tree</field>
<field name="inherit_id" ref="<base_module_name>.test_base_tree"/>
<field name="arch" type="xml">
<field name="email" position="after">
<field name="dept"/>
</field>
</field>
</record>
Here base_module_name is the name of the module where the original view with id test_base_tree is defined. If it is in the same module then no need to provide the module name, just the view id. In this way you can also inherit the form view.
Upvotes: 2