openerp视图继承

Inheritance in Views

When you create and inherit objects in some custom or specificmodules, it is better to inherit (than to replace) from an existingview to add/modify/delete some fields and preserve the others.

Example:  
<record model="ir.ui.view" id="view_partner_form">
    <field name="name">res.partner.form.inherit</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <notebook position="inside">
            <page string="Relations">
                <field name="relation_ids" colspan="4" nolabel="1"/>
            </page>
        </notebook>
    </field>
</record>

This will add a page to the notebook ofthe res.partner.form viewin the base module.

The inheritance engine will parse the existing view and search forthe root nodes of

<field name="arch" type="xml">

It will append or edit the content of this tag. If this tag hassome attributes, it will look in the parent view for a node withmatching attributes (except position).

You can use these values in the position attribute:

  • inside (default): your values will be appended inside the tag
  • after: add the content after the tag
  • before: add the content before the tag
  • replace: replace the content of the tag.

Replacing Content

<record model="ir.ui.view" id="view_partner_form1">
    <field name="name">res.partner.form.inherit1</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <page string="Extra Info" position="replace">
            <field name="relation_ids" colspan="4" nolabel="1"/>
        </page>
    </field>
</record>

Will replace the content of the Extra Info tab of the notebook withthe relation_idsfield.

The parent and the inherited views are correctly updatedwith --update=all argumentlike any other views.

Deleting Content

To delete a field from a form, an empty elementwith position="replace" attributeis used. Example:

<record model="ir.ui.view" id="view_partner_form2">
    <field name="name">res.partner.form.inherit2</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <field name="lang" position="replace"/>
    </field>
</record>

Inserting Content

To add a field into a form before the specified taguse position="before" attribute.

<record model="ir.ui.view" id="view_partner_form3">
    <field name="name">res.partner.form.inherit3</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <field name="lang" position="before">
            <field name="relation_ids"/>
        </field>
    </field>
</record>

Will add relation_ids fieldbefore the lang field.

To add a field into a form after the specified taguse position="after" attribute.

<record model="ir.ui.view" id="view_partner_form4">
    <field name="name">res.partner.form.inherit4</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <field name="lang" position="after">
            <field name="relation_ids"/>
        </field>
    </field>
</record>

Will add relation_ids fieldafter the lang field.

Multiple Changes

To make changes in more than one location, wrap the fields in adata element.

 m<record model="ir.ui.view" id="view_partner_form5">
    <field name="name">res.partner.form.inherit5</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <data>
            <field name="lang" position="replace"/>
            <field name="website" position="after">
                <field name="lang"/>
            </field>
        </data>
    </field>
</record>

Will delete the lang fieldfrom its usual location, and display it afterthe website field.

XPath Element

Sometimes a view is too complicated to let you simply identify atarget field by name. For example, the field might appear in twoplaces. When that happens, you can usean xpath elementto describe where your changes should be placed.

<record model="ir.ui.view" id="view_partner_form6">
    <field name="name">res.partner.form.inherit6</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <data>
            <xpath
                expr="//field[@name='address']/form/field[@name='email']"
                position="after">
                <field name="age"/>
            </xpath>
            <xpath
                expr="//field[@name='address']/tree/field[@name='email']"
                position="after">
                <field name="age"/>
            </xpath>
        </data>
    </field>
</record>

Will add the age fieldafter the email fieldin both the form and tree view of the address list.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值