117 lines
4.8 KiB
Python
117 lines
4.8 KiB
Python
import datetime
|
|
|
|
from odoo import api, models
|
|
|
|
|
|
class ParkingFeeCurrentMonthReceivable(models.Model):
|
|
_inherit = 'property.accounts.receivable'
|
|
|
|
@api.model
|
|
def get_parking_fee_current_month_receivable(self, params):
|
|
"""
|
|
停车费本月应收:
|
|
- 默认过滤当月应收日期;可用 date_start/date_end 覆盖
|
|
- 默认管理类型名称含“车”,也可传 management_type_id 精确指定
|
|
- 金额取应收 original_amount
|
|
"""
|
|
domain = []
|
|
|
|
# 关键词
|
|
keyword = params.get("keyword")
|
|
# summary_only:看板只取 stats 不构建 rows
|
|
summary_only = params.get("summary_only", False)
|
|
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
|
|
|
|
domain.append(("due_date", ">=", start_dt))
|
|
domain.append(("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:
|
|
type_domain = domain + [('management_type_id', '=', management_type_id)]
|
|
else:
|
|
parking_types = self.env['yuthon.management.type'].search([('name', 'ilike', '车')])
|
|
if parking_types:
|
|
type_domain = domain + [('management_type_id', 'in', parking_types.ids)]
|
|
else:
|
|
type_domain = domain[:]
|
|
|
|
receivables = self.search(type_domain, limit=2000, order="due_date asc")
|
|
if not receivables and type_domain != domain:
|
|
receivables = self.search(domain, limit=2000, order="due_date asc")
|
|
|
|
rows = []
|
|
total_amount = 0.0
|
|
# summary_only:跳过 rows 构建,直接算 stats
|
|
if summary_only:
|
|
total_amount = sum(rec.original_amount or 0.0 for rec in receivables)
|
|
return {"rows": [], "stats": [{"name": "合计", "amount": round(total_amount, 2)}]}
|
|
for idx, rec in enumerate(receivables, start=1):
|
|
amount = rec.original_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.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 "",
|
|
"金额": round(amount, 2),
|
|
"应收金额": round((rec.original_amount or 0.0) - (rec.discount_amount or 0.0), 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,
|
|
"stats": [
|
|
{"name": "合计", "amount": round(total_amount, 2)},
|
|
],
|
|
}
|
|
|