105 lines
3.8 KiB
Python
105 lines
3.8 KiB
Python
import datetime
|
|
|
|
from odoo import api, models
|
|
|
|
|
|
class CurrentMonthReceivedReport(models.Model):
|
|
_inherit = 'property.accounts.receivable'
|
|
|
|
@api.model
|
|
def get_current_month_received_report(self, params):
|
|
"""归属本月实收报表:按收款日期筛选已收金额。"""
|
|
domain = []
|
|
|
|
keyword = params.get("keyword")
|
|
if keyword:
|
|
domain += [
|
|
'|', '|',
|
|
('contract_id.contract_code', 'ilike', keyword),
|
|
('property_name', 'ilike', keyword),
|
|
('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 += [
|
|
'|',
|
|
'&', ('payout_date', '>=', start_dt), ('payout_date', '<=', end_dt),
|
|
'&', ('payout_date', '=', False), '&', ('due_date', '>=', start_dt), ('due_date', '<=', end_dt)
|
|
]
|
|
elif start_dt:
|
|
domain += [
|
|
'|',
|
|
('payout_date', '>=', start_dt),
|
|
'&', ('payout_date', '=', False), ('due_date', '>=', start_dt)
|
|
]
|
|
elif end_dt:
|
|
domain += [
|
|
'|',
|
|
('payout_date', '<=', end_dt),
|
|
'&', ('payout_date', '=', False), ('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(('tenure_type', '=', condition))
|
|
if partner_id:
|
|
domain.append(('precinct_id', '=', partner_id))
|
|
if company_id:
|
|
domain.append(('company_id', '=', company_id))
|
|
if management_type_id:
|
|
domain.append(('management_type_id', '=', management_type_id))
|
|
|
|
receivables = self.search(domain, order="payout_date asc, due_date asc")
|
|
|
|
rows = []
|
|
total_amount = 0.0
|
|
|
|
for idx, rec in enumerate(receivables, start=1):
|
|
amount = rec.delivered1 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.contract_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 "",
|
|
"金额": round(amount, 2),
|
|
"所属公司": rec.company_id.referred if rec.company_id and hasattr(rec.company_id, 'referred') 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.admin_id else "",
|
|
})
|
|
|
|
return {
|
|
"rows": rows,
|
|
"summary": {
|
|
"序号": False,
|
|
"合同编号": "合计",
|
|
"物业名称": False,
|
|
"承租方名称": False,
|
|
"金额": round(total_amount, 2),
|
|
"所属公司": False,
|
|
"管理员": False,
|
|
}
|
|
}
|
|
|