113 lines
4.5 KiB
Python
113 lines
4.5 KiB
Python
import datetime
|
|
|
|
from odoo import api, models
|
|
|
|
|
|
class MonthlyManagementFeeReport(models.Model):
|
|
_inherit = 'property.accounts.receivable'
|
|
|
|
@api.model
|
|
def get_monthly_management_fee_report(self, params):
|
|
"""
|
|
本月支出-管理费:
|
|
- 默认统计当月,支持 date_start/date_end 覆盖
|
|
- 管理类型默认匹配名称含“管/管理/物管”,可传 management_type_id 精确指定
|
|
- 金额取 original_amount
|
|
- 日期优先收款日期 payout_date,若无则应收日期 due_date
|
|
- 备注取 remark
|
|
"""
|
|
domain = []
|
|
|
|
keyword = params.get("keyword")
|
|
if keyword:
|
|
domain += [
|
|
'|', '|',
|
|
('contract_id.contract_code', 'ilike', keyword),
|
|
('property_name', 'ilike', keyword),
|
|
('lessee_id.name', 'ilike', keyword),
|
|
]
|
|
|
|
# 当月时间范围
|
|
today = datetime.date.today()
|
|
month_start = today.replace(day=1)
|
|
if month_start.month == 12:
|
|
month_end = month_start.replace(year=month_start.year + 1, month=1) - datetime.timedelta(days=1)
|
|
else:
|
|
month_end = month_start.replace(month=month_start.month + 1) - datetime.timedelta(days=1)
|
|
|
|
date_start = params.get("date_start")
|
|
date_end = params.get("date_end")
|
|
start_dt = datetime.datetime.fromisoformat(date_start).date() if date_start else month_start
|
|
end_dt = datetime.datetime.fromisoformat(date_end).date() if date_end else month_end
|
|
|
|
date_domain = [
|
|
'|',
|
|
'&', ('payout_date', '>=', start_dt), ('payout_date', '<=', end_dt),
|
|
'&', ('payout_date', '=', False), ('due_date', '>=', start_dt), ('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')
|
|
|
|
base_domain = []
|
|
if condition:
|
|
base_domain.append(('tenure_type', '=', condition))
|
|
if partner_id:
|
|
base_domain.append(('precinct_id', '=', partner_id))
|
|
if company_id:
|
|
base_domain.append(('company_id', '=', company_id))
|
|
|
|
if management_type_id:
|
|
type_domain = base_domain + [('management_type_id', '=', management_type_id)]
|
|
else:
|
|
mgmt_types = self.env['yuthon.management.type'].search([
|
|
'|', '|',
|
|
('name', 'ilike', '管'),
|
|
('name', 'ilike', '管理'),
|
|
('name', 'ilike', '物管'),
|
|
])
|
|
if mgmt_types:
|
|
type_domain = base_domain + [('management_type_id', 'in', mgmt_types.ids)]
|
|
else:
|
|
type_domain = base_domain[:]
|
|
|
|
receivables = self.search(type_domain + date_domain, limit=2000, order="payout_date asc, due_date asc")
|
|
if not receivables and type_domain != base_domain:
|
|
receivables = self.search(base_domain + date_domain, limit=2000, order="payout_date asc, due_date asc")
|
|
if not receivables and type_domain != base_domain:
|
|
receivables = self.search(base_domain, limit=2000, order="payout_date asc, due_date asc")
|
|
|
|
rows = []
|
|
total_amount = 0.0
|
|
for idx, rec in enumerate(receivables, start=1):
|
|
amount = rec.original_amount or 0.0
|
|
total_amount += amount
|
|
pay_date = rec.payout_date or rec.due_date
|
|
rows.append({
|
|
"序号": idx,
|
|
"编码": rec.contract_id.contract_code if rec.contract_id else rec.code if hasattr(rec, 'code') else "",
|
|
"日期": pay_date.strftime("%Y-%m-%d") if pay_date else "",
|
|
"物业名称": rec.property_name or "",
|
|
"金额": round(amount, 2),
|
|
"备注": rec.remark or "",
|
|
"所属公司": rec.company_id.referred if rec.company_id and hasattr(rec.company_id, 'referred') else rec.company_id.name if rec.company_id else "",
|
|
"管理员": rec.admin_id.name if rec.admin_id else "",
|
|
})
|
|
|
|
return {
|
|
"rows": rows,
|
|
"summary": {
|
|
"序号": False,
|
|
"编码": False,
|
|
"日期": False,
|
|
"物业名称": False,
|
|
"金额": round(total_amount, 2),
|
|
"备注": False,
|
|
"所属公司": False,
|
|
"管理员": False,
|
|
}
|
|
}
|
|
|