如何在 Odoo 中使用 XPath
How to use XPath in Odoo
我在 Odoo 中遇到一些问题
<record id="lunch_order_view_form" model="ir.ui.view">
<field name="name">lunch.order.form</field>
<field name="model">lunch.order</field>
<field name="arch" type="xml">
<form string='Orders Form' class="o_lunch">
<header>
<button name="%(action_lunch_order_line_lucky)d" type="action" string="Feeling Lucky" class="oe_highlight"/>
<!-- HERE THAT I WANT TO ADD -->
然后我用
<record id="lunch_order_view_form" model="ir.ui.view">
<xpath expr="/lunch/views/lunch_views/field[@name='arch']" position="after">
<button name="%(action_lunch_order_line_favorite)d" type="action" string="Favorite Menu" />
hello
</xpath>
</record>
但是现在可以用了怎么定义呢?
如果 header 已经在您的 parent 表单视图中定义,您可以按如下方式继承它:
<record id="lunch_order_view_form_inherit" model="ir.ui.view">
<field name="name">lunch.order.form.inherit</field>
<field name="model">lunch.order</field>
<field name="inherit_id" ref="parent_form_module_name.lunch_order_view_form"/>
<field name="arch" type="xml">
<xpath expr="//header" position="inside">
<button name="%(action_lunch_order_line_favorite)d" type="action" string="Favorite Menu" />
</xpath>
</field>
</record>
您可以将 parent_form_module_name
替换为已定义 parent 形式的实际模块名称。
我在 Odoo 中遇到一些问题
<record id="lunch_order_view_form" model="ir.ui.view">
<field name="name">lunch.order.form</field>
<field name="model">lunch.order</field>
<field name="arch" type="xml">
<form string='Orders Form' class="o_lunch">
<header>
<button name="%(action_lunch_order_line_lucky)d" type="action" string="Feeling Lucky" class="oe_highlight"/>
<!-- HERE THAT I WANT TO ADD -->
然后我用
<record id="lunch_order_view_form" model="ir.ui.view">
<xpath expr="/lunch/views/lunch_views/field[@name='arch']" position="after">
<button name="%(action_lunch_order_line_favorite)d" type="action" string="Favorite Menu" />
hello
</xpath>
</record>
但是现在可以用了怎么定义呢?
如果 header 已经在您的 parent 表单视图中定义,您可以按如下方式继承它:
<record id="lunch_order_view_form_inherit" model="ir.ui.view">
<field name="name">lunch.order.form.inherit</field>
<field name="model">lunch.order</field>
<field name="inherit_id" ref="parent_form_module_name.lunch_order_view_form"/>
<field name="arch" type="xml">
<xpath expr="//header" position="inside">
<button name="%(action_lunch_order_line_favorite)d" type="action" string="Favorite Menu" />
</xpath>
</field>
</record>
您可以将 parent_form_module_name
替换为已定义 parent 形式的实际模块名称。