This question has been flagged
2 Replies
17747 Views

i want to use one field in 'hr.contract' module to 'hr.employee' module.

field name in 'hr.contract' is type_id. i want to use this field in 'hr.employee' .

is this correct?

from openerp import models, fields, api, _
class Hremployee(models.Model):
    _inherit=['hr.employee','hr.contract']

 

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
        <record model="ir.ui.view" id="employee_registration_form_view1234">
            <field name="name">Employee Registration</field>
            <field name="model">hr.employee</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="hr.view_employee_form" />
            <field name="arch" type="xml">
                <xpath
                    expr="//form/sheet/div[@class='oe_title']/field[@name='work_phone']"
                    position="after">
                    <label for="employee" />
                    <field name="employee" />
                </xpath>
                
                 <xpath
                    expr="//form/sheet/div[@class='oe_title']/field[@name='employee']" position="after">
                    <label for="type_id" />
                    <field name="type_id" />
                </xpath>

            </field>

        </record>

    
        <act_window name="Employee" domain="[('employee', '=', True)]"
            res_model="hr.employee" context="{'default_employee': True}" id="employee_action1234" view_mode="tree,form"/>


        <menuitem name="Add Employee" id="add_e6hjfgjf1234" parent="check_sub_menu"
            action="employee_action1234">
        </menuitem>
    </data>
</openerp>

Avatar
Discard
Best Answer

You don't inherit fields.  If you see, the one hr.contract has one hr.employee.  Hence an hr.employee can have multiple contracts.  The type_id field is a many2one field to hr.contract.type.

  • If you need to have the type_id field in hr.employee and the content of which has nothing to do with the employee's contract, then you can just add (copy) the type_id field from hr.contract to hr.employee.  To do so, you need to inherit the hr.employee model.
  • If you need to see what are the employee's contract type, you can just show the Contracts (contract_ids) field in hr.employee's view and display the type_id field.
  • If you need to see what is the type_id of the lastest contract (by date_start) that employee is attached to, there is another field called contract_id in hr.employee.  You can add a related field via contract_id to get the type_id of the latest contract.
Avatar
Discard
Author

ok thnks