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

Odoo 17中如何仅隐藏factura_especial类型发票的红字冲销按钮

解决红字冲销按钮仅在特定发票类型隐藏的问题

问题分析

你当前的代码导致所有场景下的红字冲销按钮被隐藏,核心原因有两点:

  • XPath 未限制模型范围,定位到了所有单据(包括非发票类)中的 action_reverse 按钮,而这些非发票模型不存在 factura_especial 字段,Odoo 对无效域表达式的处理逻辑会默认隐藏按钮
  • 域表达式的评估逻辑在部分场景下未符合预期

解决方案

方案1:限制XPath仅作用于发票模型视图

通过在XPath中指定目标模型,确保只修改发票(account.move)视图内的按钮:

<xpath expr="//form[@model='account.move']//button[@name='action_reverse']" position="attributes">
    <attribute name="invisible">[("factura_especial", "=", True)]</attribute>
</xpath>

方案2:使用Python布尔表达式替代域表达式

如果 factura_especial 是发票模型的布尔字段,直接使用Python表达式更直观,还能避免字段不存在时的异常:

<xpath expr="//button[@name='action_reverse']" position="attributes">
    <attribute name="invisible">factura_especial</attribute>
</xpath>

进阶精确控制(可选)

如果需要同时限定单据为发票类型(区分收款单/付款单),可以结合 move_type 字段做双重校验:

<xpath expr="//form[@model='account.move']//button[@name='action_reverse']" position="attributes">
    <attribute name="invisible">[("factura_especial", "=", True), ("move_type", "in", ['out_invoice', 'in_invoice'])]</attribute>
</xpath>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 18:40:00