如何在Odoo中使用XPath

时间:2017-11-22 02:32:20

标签: openerp odoo-8 odoo-10

我在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>

但它现在如何定义呢?

1 个答案:

答案 0 :(得分:2)

如果已在父窗体视图中定义标头,则可以按如下方式继承它:

<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替换为您已定义父表单的实际模块名称。