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

Odoo特殊发票仅显示指定日记账的配置问题

问题分析

你的journal_id字段domain未生效,核心原因有两点:

  1. Odoo原生account.view_move_form视图中,journal_id字段自带动态domain(例如根据发票类型move_type过滤对应日记账),直接替换domain会被原生逻辑覆盖。
  2. 可能你的XPath定位不够精确,未准确匹配到表单中的目标journal_id字段。
解决方案

1. 精确匹配字段并扩展Domain

不要直接替换原domain,而是在原生过滤条件基础上叠加你的特殊日记账筛选规则,既保留供应商发票的原生逻辑,又只显示标记为facturas_especiales=True的日记账。修改XPath部分如下:

<xpath expr="//field[@name='journal_id']" position="attributes">
    <attribute name="domain">['&amp;', ('facturas_especiales', '=', True), ('type', 'in', ['purchase'])]</attribute>
</xpath>

这里用&逻辑运算符结合两个条件:一是你的布尔字段过滤,二是保留供应商发票对应的日记账类型(purchase),确保结果符合特殊发票的需求。

2. 动态适配发票状态(可选)

如果希望仅在创建/查看特殊发票时应用该过滤,普通发票保持原生逻辑,可以结合factura_especial字段的值动态设置domain:

<xpath expr="//field[@name='journal_id']" position="attributes">
    <attribute name="domain">[('facturas_especiales', '=', True) if factura_especial else ('type', 'in', ['purchase'])]</attribute>
</xpath>

当factura_especial为True时,只显示特殊日记账;为False时,恢复原生供应商日记账过滤规则。

3. 提升视图继承优先级

确保你的视图不会被其他模块的继承视图覆盖,可在视图记录中添加priority字段,设置为比原生视图更高的值(原生视图通常为10,建议设为16):

<record id="account_move_special_invoice_form_view" model="ir.ui.view">
    <field name="name">account.move.special.invoice.view</field>
    <field name="model">account.move</field>
    <field name="inherit_id" ref="account.view_move_form"/>
    <field name="priority">16</field> <!-- 提高优先级 -->
    <field name="arch" type="xml">
        <!-- 你的其他视图修改内容 -->
    </field>
</record>

4. 验证XPath定位准确性

若上述修改仍不生效,可能是XPath未精准匹配字段。可通过开发者模式查看account.view_move_form的XML结构,使用更精确的路径定位,例如结合字段所在的分组或页面:

<xpath expr="//page[@name='invoice_form']//group[@name='invoice_info']//field[@name='journal_id']" position="attributes">
    <attribute name="domain">['&amp;', ('facturas_especiales', '=', True), ('type', 'in', ['purchase'])]</attribute>
</xpath>
额外检查点
  • 确认account.journal模型的facturas_especiales字段已正确创建,且目标日记账已标记该字段为True。
  • 清除浏览器缓存并重新加载Odoo页面,确保视图修改生效。

内容的提问来源于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 14:37:12