Reputation: 157
I have a created my own module as Test_Module.
further I have inheritated hr_holidays class and view to Test_Module.
For inheritated view , i added new field Employee_Name.As per design this field pulls out all the employee names from my customized module.
however inheritated view also got Employee field which has come as part of inheritation.
Is there any way to remove this field, employee ?.I don't want to use this field employee , instead i want to use field added by me employee_name,
infact I tried by removing the inheritated field employee but no luck. System throws error saying that user_id doesn't exist in test.base
. Further I checked user_id
is used in hr_holidays class methods. I would like to know the solution from the experts. Thanks
.py file
rom 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.char('code'),
'sal':fields.float('Salary'),
'rate':fields.selection([(10,'10'),(20,'20'),(30,'30')],'rate'),
'ded':fields.float('ded'),
'ns':fields.float('Net Salary'),
'skillid':fields.one2many('test.performance','exp','Skill'),
'emphistory':fields.many2many('best.base','test_best_rel','emphistory','pc','Employee history'),
}
def rate_change(self, cr, uid, ids,rate,sal, context=None):
x = 0.0
ns=sal
if rate:
x=rate*sal
x=x/100
ns=sal-x
return {'value':{'ded':x,'ns':ns}}
test_base()
class test_plus(osv.osv):
_name='test.plus'
_columns={
'name':fields.many2one('test.base','Name'),
'bonus':fields.float('bonus'),
'salary':fields.float('Salary'),
'totalsal':fields.float('Total Salary'),
}
def name_change(self, cr, uid, ids,name, context=None):
cr.execute('select sal from test_base where id=%s', (name,))
salary= cr.fetchone()[0]
return {'value': {'salary':salary}}
def get_sum(self, cr, uid, ids,context=None):
sum = 0.0
for data in self.browse(cr, uid, ids, context=context):
sum += data.salary + data.bonus
self.write(cr, uid, ids, {'totalsal':sum})
return True
test_plus()
class test_performance(osv.osv):
_name='test.performance'
_columns={
'tech':fields.char('Technology'),
'exp':fields.integer('Experience'),
}
test_performance()
class hr_holidays(osv.osv):
_name='hr.holidays'
_inherit="hr.holidays"
_columns={
'employee_id':fields.many2one('test.base','Employee Name'),
}
hr_holidays()
xml file
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="edit_holiday_new_inheirt">
<field name="name">hr.holidays.form</field>
<field name="model">hr.holidays</field>
<field name="type">form</field>
<field name="inherit_id" ref="hr_holidays.edit_holiday_new"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="employee_name" />
</field>
</field>
</record>
<record model="ir.ui.view" id="edit_holiday_new_inheirt">
<field name="name">hr.holidays.tree</field>
<field name="model">hr.holidays</field>
<field name="type">tree</field>
<field name="inherit_id" ref="hr_holidays.edit_holiday_new"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="employee_name" />
</field>
</field>
</record>
<record model="ir.actions.act_window" id="action_test_seq44">
<field name="name">hr holidays</field>
<field name="res_model">hr.holidays</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
</record>
<record model="ir.ui.view" id="test_performance_tree">
<field name="name">test.performance.form</field>
<field name="model">test.performance</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Test performance">
<field name="tech"/>
<field name="exp"/>
</form>
</field>
</record>
<record model="ir.ui.view" id="test_performance_tree">
<field name="name">test.performance.tree</field>
<field name="model">test.performance</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Test performance">
<field name="tech"/>
<field name="exp"/>
</tree>
</field>
</record>
<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="rate_change(rate,sal)"/>
<field name="ded" />
<field name="ns"/>
<newline />
<notebook colspan="4">
<page string="Employee Skills">
<field name="skillid" nolabel="1"/>
</page>
<page string="Employement History">
<field name="emphistory" nolabel="1"/>
</page>
</notebook>
</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="ns"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="test_plus_form">
<field name="name">test.plus.form</field>
<field name="model">test.plus</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Test Plus">
<field name="name" on_change="name_change(name)" />
<field name="bonus"/>
<field name="salary"/>
<field name="totalsal"/>
<button name="get_sum" string="Sum" type="object"/>
<button name="318" string="shri" type="action"/>
</form>
</field>
</record>
<record model="ir.ui.view" id="test_plus_tree">
<field name="name">test.plus.tree</field>
<field name="model">test.plus</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Test Plus">
<field name="name"/>
<field name="bonus"/>
</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">form,tree</field>
</record>
<record model="ir.actions.act_window" id="action_test_seq1">
<field name="name">Test Plus</field>
<field name="res_model">test.plus</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
</record>
<record model="ir.actions.act_window" id="action_test_seq2">
<field name="name">Test Performance</field>
<field name="res_model">test.performance</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
</record>
<menuitem id="menu_test_base_main" name="Test Base">
</menuitem>
<menuitem id="menu_test_base_sub" parent="menu_test_base_main" name="Employee">
</menuitem>
<menuitem id="menu_test_sal" parent="menu_test_base_sub"
name="Employee Salary " action="action_test_seq"/>
<menuitem id="menu_test_bonus" parent="menu_test_base_sub"
name="Bonus Structure" action="action_test_seq1"/>
<menuitem id="menu_test_skill" parent="menu_test_base_sub"
name="Employee Skills" action="action_test_seq2"/>
<menuitem id="menu_test_hr" parent="menu_test_base_sub"
name="Employee leave" action="action_test_seq44"/>
</data>
</openerp>
Upvotes: 0
Views: 772
Reputation: 179
I was able to resolve this .
Here is the solution:
Added one more class inherited with hr.employee
class hr_employee(osv.osv):
_name='hr.employee'
_inherit='hr.employee'
_columns={
}
hr_employee()
Also made the following changes in test.base
class test_base(osv.osv):
_name='test.base'
_columns={
'name':fields.many2one('hr.employee','employee_id'),
'email':fields.char('Email'),
'code':fields.char('code'),
'sal':fields.float('Salary'),
'rate':fields.selection([(10,'10'),(20,'20'),(30,'30')],'rate'),
'ded':fields.float('ded'),
'ns':fields.float('Net Salary'),
'skillid':fields.one2many('test.performance','exp','Skill'),
'emphistory':fields.many2many('best.base','test_best_rel','emphistory','pc','Employee history'),
'department_id':fields.integer('Department'),
}
class hr_holidays(osv.osv):
_name='hr.holidays'
_inherit="hr.holidays"
_columns={
}
hr_holidays()
Upvotes: 1
Reputation: 2393
In your view definition in the XML file where you inherited from the hr_holidays.edit_holiday_new
view you put that to add a new field:
<field name="name" position="after">
<field name="employee_name" />
</field>
The magic word you need here is replace
. When you specify where to put the new field (employee_name
in your case) you can put it in the place of the old one:
<field name="name" position="replace">
<field name="employee_name" />
</field>
Upvotes: 0