Odoo模块全局计税:amount_total字段未更新问题求助
Odoo发票全局税费计算:amount_total更新异常修复方案
问题根源
你调用了原生的_compute_amount方法,该方法会基于发票行项目重新计算amount_total,直接覆盖你设置的custom_total_amount值,这就是amount_total无法更新的核心原因。而amount_residual不受影响,是因为原生逻辑不会主动修改该字段的自定义赋值。
修复方案
直接移除原生方法调用,完全替换为自定义计算逻辑:
@api.depends('custom_total_amount', 'amount_paid') def _compute_amount(self): for record in self: record.amount_total = record.custom_total_amount record.amount_residual = record.custom_total_amount - record.amount_paid amount_total = fields.Monetary(string='Total', compute='_compute_amount', store=True) amount_residual = fields.Monetary(string='Amount Due', compute='_compute_amount', store=True)
额外检查项
- 确认
custom_total_amount字段的计算逻辑正确,已包含全局税费,且依赖字段配置完整(若为计算字段) - 排查是否有其他第三方模块重写了
_compute_amount方法,导致逻辑冲突 - 若需要保留原生方法对其他字段的计算逻辑,可在调用
super后再次覆盖amount_total的值:
注:这种场景下需确保原生方法调用后没有其他逻辑二次修改@api.depends('custom_total_amount', 'amount_paid') def _compute_amount(self): super(InvoiceExtension, self)._compute_amount() for record in self: record.amount_total = record.custom_total_amount record.amount_residual = record.custom_total_amount - record.amount_paidamount_total
内容的提问来源于stack exchange,提问作者knoppix
相关产品推荐
相关产品推荐

