如何在我们自己的模块中继承特定的视图?奥多

How to inherit particular view in our own module? ODOO

大家早上好,我想继承一些来自ODOO视图的视图。这样我就可以使用我自己的模块。谁能给我解释一下,有什么可能的方法吗?

提前致谢!

查看继承

Odoo 不是修改现有视图(通过覆盖它们),而是提供视图继承,其中子视图 "extension" 应用在根视图之上,并且可以添加或删除其父视图的内容。

扩展视图使用 inherit_id 字段引用其父视图,而不是单个视图,其 arch 字段由任意数量的 xpath 元素组成,选择和更改其父视图的内容:

<!-- improved idea categories list -->
<record id="idea_category_list2" model="ir.ui.view">
    <field name="name">id.category.list2</field>
    <field name="model">idea.category</field>
    <field name="inherit_id" ref="id_category_list"/>
    <field name="arch" type="xml">
        <!-- find field description and add the field
             idea_ids after it -->
        <xpath expr="//field[@name='description']" position="after">
          <field name="idea_ids" string="Number of ideas"/>
        </xpath>
    </field>
</record>

表达式 在父视图中选择单个元素的 XPath 表达式。如果不匹配任何元素或匹配多个元素,则引发错误 位置

Operation to apply to the matched element:

inside
    appends xpath's body at the end of the matched element
replace
    replaces the matched element by the xpath's body
before
    inserts the xpath's body as a sibling before the matched element
after
    inserts the xpaths's body as a sibling after the matched element
attributes
    alters the attributes of the matched element using special attribute elements in the xpath's body

提示

匹配单个元素时,可以直接在要查找的元素上设置position属性。下面的两个继承将给出相同的结果。

<xpath expr="//field[@name='description']" position="after">
    <field name="idea_ids" />
</xpath>

<field name="description" position="after">
    <field name="idea_ids" />
</field>

希望对您有所帮助。

这里是我如何在我的新模块中继承和使用现有视图。我想继承购买视图,所以在我的模块中我继承了 purchase.order 对象

class purchase_order(osv.osv):
_inherit="purchase.order"

//你可以像往常一样在这里添加你想要的任何字段

我继承了下面这样的视图

<record id="purchase_order_advance_invoice_inherit_form" model="ir.ui.view">
<field name="name">purchase.order.advance.invoice.inherit.form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" **ref="purchase.purchase_order_form"**/>

//这是我引用我要继承的视图的地方,你可以完成剩下的标签