104 lines
4.2 KiB
Python
104 lines
4.2 KiB
Python
import datetime
|
|
|
|
from odoo import api, models
|
|
|
|
|
|
class CurrentMonthReceivedReport(models.Model):
|
|
_inherit = 'receivable.modify.line'
|
|
|
|
@api.model
|
|
def get_current_month_received_report(self, params):
|
|
"""归属本月实收报表:按收款日期筛选已收金额。"""
|
|
domain = []
|
|
|
|
keyword = params.get("keyword")
|
|
if keyword:
|
|
domain += [
|
|
'|', '|',
|
|
('receivable_id.contract_id.contract_code', 'ilike', keyword),
|
|
('receivable_id.property_name', 'ilike', keyword),
|
|
('receivable_id.lessee_id.name', 'ilike', keyword),
|
|
]
|
|
|
|
date_start = params.get("date_start")
|
|
date_end = params.get("date_end")
|
|
start_dt = datetime.datetime.fromisoformat(date_start).date() if date_start else None
|
|
end_dt = datetime.datetime.fromisoformat(date_end).date() if date_end else None
|
|
if start_dt and end_dt:
|
|
# 优先按收款日期过滤;若收款日期为空,则按应收日期兜底
|
|
domain += [
|
|
'|',
|
|
'&', ('receivable_id.payout_date', '>=', start_dt), ('receivable_id.payout_date', '<=', end_dt),
|
|
'&', ('receivable_id.payout_date', '=', False), '&', ('receivable_id.due_date', '>=', start_dt), ('receivable_id.due_date', '<=', end_dt)
|
|
]
|
|
elif start_dt:
|
|
domain += [
|
|
'|',
|
|
('receivable_id.payout_date', '>=', start_dt),
|
|
'&', ('receivable_id.payout_date', '=', False), ('receivable_id.due_date', '>=', start_dt)
|
|
]
|
|
elif end_dt:
|
|
domain += [
|
|
'|',
|
|
('receivable_id.payout_date', '<=', end_dt),
|
|
'&', ('receivable_id.payout_date', '=', False), ('receivable_id.due_date', '<=', end_dt)
|
|
]
|
|
|
|
condition = params.get('condition')
|
|
partner_id = params.get('partner_id')
|
|
company_id = params.get('company_id')
|
|
management_type_id = params.get('management_type_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 management_type_id:
|
|
domain.append(('receivable_id.management_type_id', '=', management_type_id))
|
|
|
|
lines = self.search(domain, order="receivable_id asc")
|
|
|
|
rows = []
|
|
total_amount = 0.0
|
|
|
|
for idx, line in enumerate(lines, start=1):
|
|
rec = line.receivable_id
|
|
amount = line.amount or 0.0 # 已对金额
|
|
total_amount += amount
|
|
|
|
rows.append({
|
|
"序号": idx,
|
|
"合同编号": {
|
|
'model': 'property.lease.contract',
|
|
'id': rec.contract_id.id,
|
|
'display_name': rec.contract_id.contract_code,
|
|
} if rec and 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 "",
|
|
"承租方名称": {
|
|
'model': 'property.tenant.information',
|
|
'id': rec.lessee_id.id,
|
|
'display_name': rec.lessee_id.name,
|
|
} if rec and rec.lessee_id else "",
|
|
"金额": round(amount, 2),
|
|
"所属公司": rec.company_id.referred if rec and rec.company_id and hasattr(rec.company_id, 'referred') else rec.company_id.name if rec and 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 "",
|
|
})
|
|
|
|
return {
|
|
"rows": rows,
|
|
"stats": [
|
|
{"name": "实收总额", "amount": round(total_amount, 2)},
|
|
],
|
|
}
|
|
|