Skip to Content
Menu
This question has been flagged
7 Replies
19257 Views

Hello, 

I have created a module in odoo, and the original views have changed, now I want to create an other module that can inherits the original views, I tried <field name=" mode">primary</field> but I got only the original view, no changes. Plz help me

Avatar
Discard

Inheritance in model and views: https://goo.gl/4Zyc9d

Best Answer

When you create a new module and if you want to inherit the fields in the basic view you need to call the reference of the form view.

<field name=”inherit_id” ref=”module_name.id_of_form_view”/>​​​

Example:



<record id="move_form_view" model="ir.ui.view">
<field name="name">move_form_view</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='action_quotation_send']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
</field>
</record>
Avatar
Discard
Best Answer

hello,

you can use :

<field name=”inherit_id” ref=”module_name.id_of view”/>

here is a simple example to inherit sale order form view :

<record model=”ir.ui.view” id=”sale_order_custom_field”>
    <field name=”name”>sale.order.form</field>
    <field name=”model”>sale.order</field>
    <field name=”inherit_id” ref=”sale.view_order_form”/>
    <field name=”arch” type=”xml”>
        <xpath expr=”//field[@name='partner_id']” position=”after”>
            <field name=”sale_project_ids”/>
        </xpath>
</field>
</record>

Avatar
Discard
Best Answer

Hi,
If you create a module with name A, and you inherit its form view by
<field name=”inherit_id” ref=”mrp.mrp_production_form_view”/>
after inheriting it you change the form view as you like, Mr. Amal already provide a perfect code.

<record id="mrp_production_form_view_inherits" model="ir.ui.view">
 <field name="name">mrp.production.form</field>
 <field name="model">mrp.production</field>
<field name=”inherit_id” ref=”mrp.mrp_production_form_view”/>
<field name="arch" type="xml">
.........................................................................
.........................................................................
</field> 

 After that you want it create a new module with name B. and you want Inherit the same form and view, then 

<field name=”inherit_id” ref=”A.mrp_production_form_view_inherts”/>

Don't forget to add the dependancy in manifest file

'depends': ['mrp', 'A',],

thanks
Avatar
Discard
Best Answer

Hi Kawtar, if you want to inherit your original view, then in that case you need to add a field attribute called as inherit_id to your inherited view.

A = module_name_where_you_define_original_view [for understanding]

B = original_view_id [for understanding]                                                           

Syntax : <field name="inherit_id" ref="A.B"/>

Avatar
Discard
Author Best Answer

I have already created a module on odoo and this module inherits several views, these views have changed when I modified their content. Now I want to create a new module that inherits the original views but I can't access the original views. what shoud I do ? The content of the original views has changed completely

Avatar
Discard
Best Answer

In Odoo/OpenERP we can inherit or use existing modules object/class/model and views. We can also inherit single field of existing modules. The question is why we need such inheritance.

The purpose of inheritance or why we need inheritance is given below:

  • To change attributes of some fields which exists on existing/custom model (e.g. making fields readonly,invisible)

  • To add/modify/delete old or new fields in existing/custom model (e.g. Product, Sales, HR, Fleet Management, Attendance modules model etc)

  • We can also add buttons in already existing/custom model (form and tree) view by using inheritance


To model inheritance:

class groups(models.Model):
_inherit = 'res.groups'
# we inherited res.groups model which is Odoo/OpenERP built in model and created two fields in that model.
field_1 = fields.Char(required=True,string="Field One")
field_2 = fields.Boolean(default=False,string="Field Two")

Get complete code about view and model inheritance with description

http://learnopenerp.blogspot.com/2018/01/inheritance-in-models-and-views.html



Avatar
Discard
Related Posts Replies Views Activity
0
Apr 24
396
4
Nov 23
4242
0
Oct 23
377
0
Dec 22
1334
2
Dec 23
17348