Odoo14修改account.move借贷方计算逻辑后账单状态异常排查
解决Account Move借贷方计算逻辑修改后的账单状态异常问题
可能的代码错误点
你的代码大概率在修改借贷方计算逻辑时,误触发了付款状态相关的逻辑,常见情况包括:
- 直接给
account.move的payment_state字段赋值为paid,或者修改state字段时错误标记了已对账状态 - 自动创建了账单的对账分录(reconciliation),导致系统判定账单已全额付清
- 修改
account.move.line时,错误设置了reconciled字段为True
正确的借贷方计算修改方法
要只修改debit/credit的计算来源(从subtotal取数而非quantity*price_unit),需要专注于**行级(account.move.line)**的字段计算逻辑,不要触碰付款状态相关的代码。以下是示例实现:
from odoo import models, fields, api class AccountMove(models.Model): _inherit = 'account.move' @api.depends('line_ids.subtotal', 'line_ids.account_id', 'currency_id', 'date') def _compute_amount(self): # 先执行父类的金额计算逻辑,保证其他字段正常 super()._compute_amount() for move in self: company_currency = move.company_id.currency_id for line in move.line_ids: # 跳过标题、备注类行 if line.display_type in ('line_section', 'line_note'): continue # 根据科目类型确定借贷方向,从subtotal取数 subtotal = line.subtotal if line.account_id.user_type_id.type in ('receivable', 'asset'): line.debit = subtotal line.credit = 0.0 elif line.account_id.user_type_id.type in ('payable', 'liability', 'equity'): line.credit = subtotal line.debit = 0.0 # 处理多币种场景,转换为公司本位币 if move.currency_id != company_currency: converted_amount = move.currency_id._convert( subtotal, company_currency, move.company_id, move.date or fields.Date.today() ) if line.account_id.user_type_id.type in ('receivable', 'asset'): line.debit = converted_amount else: line.credit = converted_amount
异常排查步骤
- 检查你的代码,确认没有对
payment_state、reconciled、state这些和付款状态相关的字段做手动赋值 - 创建账单后,查看
account.move的payment_state字段值,以及对应的account.move.line是否被自动标记为已对账 - 查看系统日志,确认是否有自动创建付款单据或执行对账操作的记录
内容的提问来源于stack exchange,提问作者Muhammad Usman
相关产品推荐
相关产品推荐

