コンテンツへスキップ
メニュー
この質問にフラグが付けられました
7 返信
20894 ビュー

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
1925
4
11月 23
6025
0
10月 23
1769
0
12月 22
2677
2
12月 23
19422