Merge pull request !10454 from 李鹏宇/dev
This commit is contained in:
@@ -48,6 +48,9 @@ class CurrentMonthReceivedReport(models.Model):
|
||||
partner_id = params.get('partner_id')
|
||||
company_id = params.get('company_id')
|
||||
management_type_id = params.get('management_type_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))
|
||||
@@ -55,6 +58,12 @@ class CurrentMonthReceivedReport(models.Model):
|
||||
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))
|
||||
if management_type_id:
|
||||
domain.append(('receivable_id.management_type_id', '=', management_type_id))
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
import calendar
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
@@ -11,46 +12,72 @@ class DepositMonthReceivableReport(models.Model):
|
||||
"""
|
||||
押金本月应收报表:
|
||||
- 管理费用类型为"押金"
|
||||
- 应收开始时间在查询月中
|
||||
- 金额取应收账单的原始金额
|
||||
- 应收日期(due_date)在查询月内
|
||||
- 必须有收款记录(reconciliation_date != False)
|
||||
- 排除跨月预收(reconciliation_date < due_date 且不同年月)
|
||||
- 金额取收款记录的 amount,按应收账单聚合
|
||||
"""
|
||||
deposit_type = self.env['yuthon.management.type'].search([('name', '=', '押金')], limit=1)
|
||||
|
||||
domain = []
|
||||
if deposit_type:
|
||||
domain.append(('management_type_id', '=', deposit_type.id))
|
||||
|
||||
date_start = params.get("date_start")
|
||||
date_end = params.get("date_end")
|
||||
if date_start:
|
||||
domain.append(('due_date', '>=', datetime.datetime.fromisoformat(date_start).date()))
|
||||
if date_end:
|
||||
domain.append(('due_date', '<=', datetime.datetime.fromisoformat(date_end).date()))
|
||||
query_date = datetime.datetime.fromisoformat(date_start).date() if date_start else datetime.date.today()
|
||||
month_first = query_date.replace(day=1)
|
||||
last_day = calendar.monthrange(query_date.year, query_date.month)[1]
|
||||
month_last = query_date.replace(day=last_day)
|
||||
|
||||
domain = [
|
||||
('reconciliation_date', '!=', False),
|
||||
('receivable_id.due_date', '>=', month_first),
|
||||
('receivable_id.due_date', '<=', month_last),
|
||||
('receivable_id.is_invalid', '=', False),
|
||||
('receivable_id.management_type_id.name', '=', '押金'),
|
||||
]
|
||||
|
||||
keyword = params.get("keyword")
|
||||
if keyword:
|
||||
domain += ['|', '|',
|
||||
('contract_id.contract_code', 'ilike', keyword),
|
||||
('property_name', 'ilike', keyword),
|
||||
('lessee_id.name', 'ilike', keyword),
|
||||
('receivable_id.contract_id.contract_code', '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')
|
||||
if condition:
|
||||
domain.append(('tenure_type', '=', condition))
|
||||
domain.append(('receivable_id.tenure_type', '=', condition))
|
||||
if partner_id:
|
||||
domain.append(('precinct_id', '=', partner_id))
|
||||
domain.append(('receivable_id.precinct_id', '=', partner_id))
|
||||
if company_id:
|
||||
domain.append(('company_id', '=', company_id))
|
||||
domain.append(('receivable_id.company_id', '=', company_id))
|
||||
|
||||
receivables = self.search(domain, order="id asc")
|
||||
lines = self.env['receivable.modify.line'].sudo().search(
|
||||
domain, order="receivable_id asc, reconciliation_date asc"
|
||||
)
|
||||
|
||||
# 排除跨月预收
|
||||
lines = lines.filtered(
|
||||
lambda l: not (
|
||||
l.reconciliation_date and l.receivable_id.due_date
|
||||
and l.reconciliation_date < l.receivable_id.due_date
|
||||
and not (
|
||||
l.reconciliation_date.year == l.receivable_id.due_date.year
|
||||
and l.reconciliation_date.month == l.receivable_id.due_date.month
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
# 按应收账单聚合
|
||||
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, rec in enumerate(receivables, start=1):
|
||||
amount = round(rec.original_amount or 0.0, 2) # 取应收账单的原始金额
|
||||
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,
|
||||
@@ -58,24 +85,24 @@ class DepositMonthReceivableReport(models.Model):
|
||||
'model': 'property.lease.contract',
|
||||
'id': rec.contract_id.id,
|
||||
'display_name': rec.contract_id.contract_code,
|
||||
} if rec and rec.contract_id else "",
|
||||
} 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 and rec.contract_id and rec.contract_id.lease_ids and rec.contract_id.lease_ids[0].address_id else rec.property_name or "",
|
||||
} 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 and rec.lessee_id else "",
|
||||
} if rec.lessee_id else "",
|
||||
"金额": amount,
|
||||
"所属公司": rec.company_id.name if rec and rec.company_id else "",
|
||||
"所属公司": 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 and rec.admin_id else "",
|
||||
} if rec.admin_id else "",
|
||||
})
|
||||
|
||||
stats = [
|
||||
|
||||
Reference in New Issue
Block a user