You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调整XPath字段位置:将Refuse按钮移至Send for Payment位置

调整费用表单中「拒绝」按钮的位置到「提交付款」按钮处

需求说明

需要调整费用表单视图的按钮顺序,将「拒绝(Refuse)」按钮移动到「提交付款(Send for Payment)」按钮的位置(对应原生代码中的「生成会计分录(Generate Accounting Entries)」按钮位置)。

原生视图代码片段

<record id="view_expenses_form" model="ir.ui.view">
    <field name="name">hr.expense.form</field>
    <field name="model">hr.expense.expense</field>
    <field eval="25" name="priority"/>
    <field name="arch" type="xml">
        <form string="Expenses Sheet">
            <header>
                <button name="confirm" states="draft" string="Submit to Manager" type="workflow" class="oe_highlight"/>
                <button name="validate" states="confirm" string="Approve" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
                <button name="refuse" states="confirm,accepted" string="Refuse" type="workflow" groups="base.group_hr_user" />
                <button name="draft" states="confirm,cancelled" string="Set to Draft" type="workflow" groups="base.group_hr_user" />
                <button name="done" states="accepted" string="Generate Accounting Entries" type="workflow" groups="account.group_account_invoice" class="oe_highlight"/>
                <button name="action_view_move" states="done" string="Open Accounting Entries" type="object" groups="account.group_account_invoice"/>
                <field name="state" widget="statusbar" statusbar_visible="draft,confirm,accepted,done,paid" statusbar_colors='{"confirm":"blue","cancelled":"red"}'/>
            </header>

解决方案代码

通过继承原视图并使用XPath调整按钮位置,无需修改原生代码:

<record id="view_expenses_form_inherit" model="ir.ui.view">
    <field name="name">hr.expense.form.inherit</field>
    <field name="model">hr.expense.expense</field>
    <field name="inherit_id" ref="hr_expense.view_expenses_form"/>
    <field name="arch" type="xml">
        <!-- 移除原位置的「拒绝」按钮 -->
        <xpath expr="//button[@name='refuse']" position="replace"/>
        
        <!-- 在「生成会计分录」按钮前插入「拒绝」按钮 -->
        <xpath expr="//button[@name='done']" position="before">
            <button name="refuse" states="confirm,accepted" string="Refuse" type="workflow" groups="base.group_hr_user" />
        </xpath>
    </field>
</record>

代码说明

  • inherit_id 指定继承的原生视图,确保修改不会破坏原代码结构
  • 第一个XPath定位到原「拒绝」按钮,用position="replace"移除它
  • 第二个XPath定位到「生成会计分录」按钮(name="done"),用position="before"在其前方插入「拒绝」按钮,完成位置调整

如果需要将「拒绝」按钮放在「生成会计分录」按钮之后,只需将position="before"改为position="after"即可。

内容的提问来源于stack exchange,提问作者MBOU LONTSI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 23:15:25