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

Is inherit key enough to use fields of the inherited classe?

By
Drees Far
on 7/28/15, 8:45 AM 460 views

Hi!!!

Please, i want to use the field name_related of HR class.

I made _inherit = ['hr.employee'] in my class, and no i need to call name_related field.

Am i obliged to inherit it also, which means recreate it in my class and add its xpath in the XML part.

Waiting your answer please.

Thanks a lot in advance.

0

Yenthe

--Yenthe--
6706
| 7 7 8
Turnhout, Belgium
--Yenthe--

My Odoo blog: http://www.odoo.yenthevg.com/

My Twitter: https://twitter.com/Yenthe666

Yenthe
On 7/28/15, 9:15 AM

Hi Drees,

I'm not exactly sure what you need to know but you should always add a reference to the correct module in your __openerp__.py. For example:

 # any module necessary for this one to work correctly
    'depends': ['external_module_name'],

After adding the name of the other module to the __openerp__.py file you can inherit the model:

class your_class_name(models.Model):
    _inherit = 'hr.employee'
    #You can add new fields here. An example:
    my_custom_field = fields.String('My custom field')

You can then create an Xpath to the view you want to inherit and add your custom view. Something along these lines:

 <record id="view_product_form_inherit" model="ir.ui.view">
            <field name="name"your.name.inherit</field>
            <field name="model">hr.employee</field>
            <field name="inherit_id" ref="module_name.template_xml_name"/>
            <field name="arch" type="xml">
		<!-- Field after other field -->
                <xpath expr="//field[@name='standard_price']" position="before">
                    <field name="my_custom_field"/>
               </xpath>
            </field>
        </record>

If you do not need to add any new fields on the existing model and only need to inherit a view you can leave the part about inheriting the model out and you can directly write an xpath expression in XML.
I hope this explains enough.
Yenthe

I want to use a field existing in hr class after inheriting the class. How can i call it?

Drees Far
on 7/28/15, 9:35 AM

Define using and calling field. In Python? In Xml? Do you want to do operations with it? When opening the record, when saving, when ... ?

Yenthe
on 7/28/15, 10:34 AM

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: 7/28/15, 8:45 AM
Seen: 460 times
Last updated: 7/29/15, 10:39 AM