Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

how to inherit field from one module to another module?

By
Demirel yakito
on 2/17/15, 7:19 AM 4,318 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>

1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 2/17/15, 7:38 AM

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.

ok thnks

Demirel yakito
on 2/17/15, 7:49 AM
0
Takwa
On 5/29/15, 6:03 AM

I want inherit customer fracture view from accounting model to another custom module!but it doesn't work!!can anybody help me please!this is my code:

from openerp.osv import fields, osv

class dimo_dimo(osv.osv):

_name = 'dimo.dimo'

_inherit = 'account.invoice.line'

dimo_dimo()

_____________________________

<record model="ir.ui.view" id="view_account_invoice_inherit_tree">

<field name="name">account.invoice.tree.inherit</field>

<field name="model">account.invoice</field>

<field name="type">tree</field>

<field name="inherit_id" ref="account.invoice_tree"/>

</record>

 


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/17/15, 7:19 AM
Seen: 4318 times
Last updated: 5/29/15, 6:03 AM