!10455 Merge branch 'dev' of <a href="https://gitee.com/jinan-pengyusen-data/gzth">https://gitee.com/jinan-pengyusen-data/gzth</a> into dev_wang
Merge pull request !10455 from 李鹏宇/dev_wang
This commit is contained in:
@@ -9,136 +9,93 @@ class DepositPreReceivedReport(models.Model):
|
||||
@api.model
|
||||
def get_deposit_pre_received_report(self, params):
|
||||
"""
|
||||
押金前期实收报表:
|
||||
- 数据源: receivable.modify.line(应收类型为押金)
|
||||
- 金额: penalty.pay.line.amount(支付金额)
|
||||
- 日期过滤: penalty.pay.line.date 在无限制至查询月上个月最后一天(不含查询月)
|
||||
押金前期实收报表(数据源:receivable.modify.line):
|
||||
- 应收类型为"押金"
|
||||
- 收款日期(reconciliation_date)在查询日期之前(不含查询月)
|
||||
- 金额取收款记录的 amount,按应收账单聚合
|
||||
"""
|
||||
date_start = params.get("date_start")
|
||||
if date_start:
|
||||
query_date = datetime.datetime.fromisoformat(date_start).date()
|
||||
else:
|
||||
query_date = datetime.date.today()
|
||||
query_date = datetime.datetime.fromisoformat(date_start).date() if date_start else datetime.date.today()
|
||||
|
||||
query_month = query_date.month
|
||||
# 前期范围:收款日期 < 查询月月初
|
||||
cutoff_date = query_date.replace(day=1)
|
||||
|
||||
# 前期范围:无限制 ~ 查询月上个月最后一天
|
||||
# 只设置结束日期,不设置开始日期,实现完全无限制
|
||||
period_end = datetime.date(query_date.year, query_month, 1) - datetime.timedelta(days=1)
|
||||
|
||||
deposit_type = self.env['yuthon.management.type'].search([('name', '=', '押金')], limit=1)
|
||||
|
||||
domain = []
|
||||
if deposit_type:
|
||||
domain.append(('management_type_id', '=', deposit_type.id))
|
||||
domain = [
|
||||
('reconciliation_date', '!=', False),
|
||||
('reconciliation_date', '<', cutoff_date),
|
||||
('receivable_id.is_invalid', '=', False),
|
||||
('receivable_id.management_type_id.name', '=', '押金'),
|
||||
]
|
||||
|
||||
keyword = params.get("keyword")
|
||||
if keyword:
|
||||
domain += ['|', '|',
|
||||
('receivable_id.contract_id.contract_code', 'ilike', keyword),
|
||||
('property_name', 'ilike', keyword),
|
||||
('receivable_id.property_name', 'ilike', keyword),
|
||||
('receivable_id.lessee_id.name', 'ilike', keyword),
|
||||
]
|
||||
|
||||
condition = params.get('condition')
|
||||
partner_id = params.get('partner_id')
|
||||
company_id = params.get('company_id')
|
||||
property_id = params.get('property_id')
|
||||
lessee_id = params.get('lessee_id')
|
||||
contract_id = params.get('contract_id')
|
||||
|
||||
if condition:
|
||||
domain.append(('receivable_id.tenure_type', '=', condition))
|
||||
if partner_id:
|
||||
domain.append(('receivable_id.precinct_id', '=', partner_id))
|
||||
if company_id:
|
||||
domain.append(('receivable_id.company_id', '=', company_id))
|
||||
if property_id:
|
||||
domain.append(('receivable_id.property_ids', 'in', [property_id]))
|
||||
if lessee_id:
|
||||
domain.append(('receivable_id.lessee_id', '=', lessee_id))
|
||||
if contract_id:
|
||||
domain.append(('receivable_id.contract_id', '=', contract_id))
|
||||
|
||||
modify_lines = self.search(domain, order="receivable_id asc")
|
||||
lines = self.sudo().search(domain, order="receivable_id asc, reconciliation_date asc")
|
||||
|
||||
# 按应收账单聚合
|
||||
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
|
||||
idx = 1
|
||||
|
||||
for line in modify_lines:
|
||||
if not line.receivable_id:
|
||||
continue
|
||||
receivable_id = line.receivable_id.id
|
||||
|
||||
rec = line.receivable_id
|
||||
wizards = self.env['penalty.line.wizard'].search(
|
||||
[('receivable_id', '=', receivable_id)]
|
||||
)
|
||||
if wizards:
|
||||
# 处理有wizard关联的记录,确保使用penalty.pay.line的字段
|
||||
for wizard in wizards:
|
||||
for pay in wizard.pay_line_ids:
|
||||
if not pay.date:
|
||||
continue
|
||||
# 确保支付类型是押金
|
||||
if pay.management_type_id and pay.management_type_id.name != '押金':
|
||||
continue
|
||||
if pay.date <= period_end:
|
||||
amount = round(pay.amount, 2)
|
||||
total_amount += amount
|
||||
rows.append({
|
||||
"序号": idx,
|
||||
"合同编号": {
|
||||
'model': 'property.lease.contract',
|
||||
'id': rec.contract_id.id if rec.contract_id else None,
|
||||
'display_name': rec.contract_id.contract_code if rec.contract_id else "",
|
||||
} if rec.contract_id else "",
|
||||
"物业名称": {
|
||||
'model': 'yuthon.property',
|
||||
'id': rec.contract_id.lease_ids[0].address_id.id if rec.contract_id and rec.contract_id.lease_ids and rec.contract_id.lease_ids[0].address_id else None,
|
||||
'display_name': rec.property_name,
|
||||
} if rec.contract_id and rec.contract_id.lease_ids and rec.contract_id.lease_ids[0].address_id else rec.property_name or "",
|
||||
"承租方名称": {
|
||||
'model': 'property.tenant.information',
|
||||
'id': rec.lessee_id.id if rec.lessee_id else None,
|
||||
'display_name': rec.lessee_id.name if rec.lessee_id else "",
|
||||
} if rec.lessee_id else "",
|
||||
"收款日期": pay.date.strftime("%Y-%m-%d"),
|
||||
"金额": amount,
|
||||
"所属公司": rec.company_id.name if rec.company_id else "",
|
||||
"管理员": {
|
||||
'model': 'res.users',
|
||||
'id': rec.admin_id.id if rec.admin_id else None,
|
||||
'display_name': rec.admin_id.name if rec.admin_id else "",
|
||||
} if rec.admin_id else "",
|
||||
})
|
||||
idx += 1
|
||||
else:
|
||||
# 如果没有关联的wizard,尝试直接从line获取信息
|
||||
if line.delivered1 and (line.receivable_id.payout_date or line.create_date):
|
||||
# 使用payout_date作为收款日期,如果没有则使用create_date
|
||||
payment_date = line.receivable_id.payout_date or line.create_date.date()
|
||||
if payment_date <= period_end:
|
||||
amount = round(line.delivered1, 2)
|
||||
total_amount += amount
|
||||
rows.append({
|
||||
"序号": idx,
|
||||
"合同编号": {
|
||||
'model': 'property.lease.contract',
|
||||
'id': rec.contract_id.id if rec.contract_id else None,
|
||||
'display_name': rec.contract_id.contract_code if rec.contract_id else "",
|
||||
} if rec.contract_id else "",
|
||||
"物业名称": {
|
||||
'model': 'yuthon.property',
|
||||
'id': rec.contract_id.lease_ids[0].address_id.id if rec.contract_id and rec.contract_id.lease_ids and rec.contract_id.lease_ids[0].address_id else None,
|
||||
'display_name': rec.property_name,
|
||||
} if rec.contract_id and rec.contract_id.lease_ids and rec.contract_id.lease_ids[0].address_id else rec.property_name or "",
|
||||
"承租方名称": {
|
||||
'model': 'property.tenant.information',
|
||||
'id': rec.lessee_id.id if rec.lessee_id else None,
|
||||
'display_name': rec.lessee_id.name if rec.lessee_id else "",
|
||||
} if rec.lessee_id else "",
|
||||
"收款日期": payment_date.strftime("%Y-%m-%d"),
|
||||
"金额": amount,
|
||||
"所属公司": rec.company_id.name if rec.company_id else "",
|
||||
"管理员": {
|
||||
'model': 'res.users',
|
||||
'id': rec.admin_id.id if rec.admin_id else None,
|
||||
'display_name': rec.admin_id.name if rec.admin_id else "",
|
||||
} if rec.admin_id else "",
|
||||
})
|
||||
idx += 1
|
||||
for idx, (rid, data) in enumerate(rec_map.items(), start=1):
|
||||
rec = data['rec']
|
||||
amount = round(data['amount'], 2)
|
||||
total_amount += amount
|
||||
rows.append({
|
||||
"序号": idx,
|
||||
"合同编号": {
|
||||
'model': 'property.lease.contract',
|
||||
'id': rec.contract_id.id,
|
||||
'display_name': rec.contract_id.contract_code,
|
||||
} if rec.contract_id else "",
|
||||
"物业名称": {
|
||||
'model': 'yuthon.property',
|
||||
'id': rec.contract_id.lease_ids[0].address_id.id,
|
||||
'display_name': rec.property_name,
|
||||
} if rec.contract_id and rec.contract_id.lease_ids and rec.contract_id.lease_ids[0].address_id else rec.property_name or "",
|
||||
"承租方名称": {
|
||||
'model': 'property.tenant.information',
|
||||
'id': rec.lessee_id.id,
|
||||
'display_name': rec.lessee_id.name,
|
||||
} if rec.lessee_id else "",
|
||||
"金额": amount,
|
||||
"所属公司": rec.company_id.name if rec.company_id else "",
|
||||
"管理员": {
|
||||
'model': 'res.users',
|
||||
'id': rec.admin_id.id,
|
||||
'display_name': rec.admin_id.name,
|
||||
} if rec.admin_id else "",
|
||||
})
|
||||
|
||||
stats = [
|
||||
{'name': '记录总数', 'amount': len(rows)},
|
||||
|
||||
Reference in New Issue
Block a user