前期欠收报表

This commit is contained in:
李鹏宇
2026-03-30 18:09:05 +08:00
parent 6dc0588d44
commit 1a2b28f4de
+30 -15
View File
@@ -10,22 +10,23 @@ class PreArrearsReport(models.Model):
def get_pre_arrears_report(self, params):
"""
前期欠收报表(数据源:receivable.modify.line):
- 应收开始日期(receivable_id.due_date)在查询月第一天之前
- 应收账单未收金额(receivable_id.submitted)> 0
- 应收账单非作废(receivable_id.is_invalid = False)
- 排除押金和违约金类型
- 金额取 original_amount(交易金额)
- 查询条件的日期对应应收账单的 due_date(应收日期在查询月内)
- 收款日期(reconciliation_date)晚于应收日期(due_date)的记录就是欠收
- 金额取收款记录的 amount
- 按应收账单聚合,每张账单只出一行(汇总该账单下所有欠收收款金额)
"""
today = datetime.date.today()
this_month_first = today.replace(day=1)
date_start = params.get("date_start")
# 前期欠收:due_date 在查询起始日期之前(若无传值则取本月第一天)
date_end = params.get("date_end")
# 应收日期在查询日期之前(不含查询月)
cutoff_date = datetime.datetime.fromisoformat(date_start).date() if date_start else this_month_first
# 核心逻辑:due_date < cutoff_date,且收款日期 > 应收日期
domain = [
('reconciliation_date', '!=', False),
('receivable_id.due_date', '<', cutoff_date),
('receivable_id.submitted', '>', 0),
('receivable_id.is_invalid', '=', False),
]
@@ -54,14 +55,28 @@ class PreArrearsReport(models.Model):
else:
domain.append(('receivable_id.management_type_id.name', 'not in', ['押金', '违约金']))
lines = self.search(domain, order="receivable_id asc")
lines = self.sudo().search(domain, order="receivable_id asc, reconciliation_date asc")
# 欠收条件:reconciliation_date > due_date(收款日期晚于应收日期)、Python过滤
lines = lines.filtered(
lambda l: l.reconciliation_date and l.receivable_id.due_date
and l.reconciliation_date > l.receivable_id.due_date
)
# 按应收账单聚合
rec_map = {}
for line in lines:
rid = line.receivable_id.id
if rid not in rec_map:
rec_map[rid] = {'rec': line.receivable_id, 'amount': 0.0}
rec_map[rid]['amount'] += line.amount or 0.0
rows = []
total_amount = 0.0
for idx, line in enumerate(lines, start=1):
rec = line.receivable_id
contract = rec.contract_id if rec else None
amount = round(rec.submitted or 0.0, 2)
for idx, (rid, data) in enumerate(rec_map.items(), start=1):
rec = data['rec']
contract = rec.contract_id
amount = round(data['amount'], 2)
total_amount += amount
# 物业穿透
@@ -88,15 +103,15 @@ class PreArrearsReport(models.Model):
'model': 'property.tenant.information',
'id': rec.lessee_id.id,
'display_name': rec.lessee_id.name,
} if rec and rec.lessee_id else "",
"收款类型": rec.management_type_id.name if rec and rec.management_type_id else "",
} if rec.lessee_id else "",
"收款类型": rec.management_type_id.name if rec.management_type_id else "",
"金额": amount,
"所属公司": contract.lessor_id.name if contract and contract.lessor_id else "",
"管理员": {
'model': 'res.users',
'id': rec.admin_id.id,
'display_name': rec.admin_id.name,
} if rec and rec.admin_id else "",
} if rec.admin_id else "",
})
stats = [