跳至內容
選單
此問題已被標幟
7 回覆
20869 瀏覽次數

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

頭像
捨棄

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

最佳答案

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>
頭像
捨棄
最佳答案

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>

頭像
捨棄
最佳答案

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
頭像
捨棄
最佳答案

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"/>

頭像
捨棄
作者 最佳答案

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

頭像
捨棄
最佳答案

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



頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
4月 24
1884
4
11月 23
6014
0
10月 23
1759
0
12月 22
2647
2
12月 23
19371