This commit is contained in:
李鹏宇
2026-03-24 18:11:51 +08:00
parent cbb3023dcb
commit a9e38afef7
+10 -4
View File
@@ -58,6 +58,9 @@ class ReceivableFlowReport(models.Model):
rec_ids = receivables.ids
# ===== 批量预加载,避免N+1查询 =====
# 0. 先查询违约金类型记录
penalty_type = self.env['yuthon.management.type'].search([('name', '=', '违约金')], limit=1)
# 1. 批量查收款明细行(sudo跳过多公司权限)
all_modify_lines = self.env['receivable.modify.line'].sudo().search([
('receivable_id', 'in', rec_ids),
@@ -169,10 +172,13 @@ class ReceivableFlowReport(models.Model):
# 违约金收款:直接从 penalty.pay.line 取(持久化数据源)
rec_penalty_pay_lines = penalty_pay_map.get(rec.id, [])
# 违约金收款金额:类型为“违约金”的金额之和
penalty_pay_collected = [
l for l in rec_penalty_pay_lines
if l.management_type_id and l.management_type_id.name == '违约金'
]
if penalty_type:
penalty_pay_collected = [
l for l in rec_penalty_pay_lines
if l.management_type_id and l.management_type_id.id == penalty_type.id
]
else:
penalty_pay_collected = []
total_penalty_collected = sum(l.amount for l in penalty_pay_collected)
# 违约金收款时间:类型为“违约金”的最新收款日期
latest_penalty_pay = sorted(