gpt4 book ai didi

python - 如何在我们自己的模块中继承特定的 View ?奥多

转载 作者:数据小太阳 更新时间:2023-10-29 02:01:29 25 4
gpt4 key购买 nike

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

提前致谢!

最佳答案

View 继承

Odoo 不是就地修改现有 View (通过覆盖它们),而是提供 View 继承,其中子“扩展” View 应用在 Root View 之上,并且可以从其父 View 添加或删除内容。

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

<!-- 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>

表达式 在父 View 中选择单个元素的 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>

希望这对您有所帮助。

关于python - 如何在我们自己的模块中继承特定的 View ?奥多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33116730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com