89 lines
3.2 KiB
Python
89 lines
3.2 KiB
Python
import datetime
|
|
|
|
from odoo import api, models
|
|
|
|
|
|
class ManagementAreaReport(models.Model):
|
|
_inherit = 'yuthon.property'
|
|
|
|
@api.model
|
|
def get_management_area_report(self, params):
|
|
"""管理面积报表数据源。"""
|
|
domain = []
|
|
|
|
keyword = params.get("keyword")
|
|
if keyword:
|
|
domain += [
|
|
'|', '|',
|
|
('name', 'ilike', keyword),
|
|
('title_deed', 'ilike', keyword),
|
|
('code', 'ilike', keyword),
|
|
]
|
|
|
|
date_start = params.get("date_start")
|
|
date_end = params.get("date_end")
|
|
end_dt = datetime.datetime.fromisoformat(date_end).date() if date_end else None
|
|
|
|
condition = params.get('condition')
|
|
partner_id = params.get('partner_id')
|
|
company_id = params.get('company_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))
|
|
|
|
properties = self.search(domain, limit=2000)
|
|
|
|
rows = []
|
|
total_rent_area = 0.0
|
|
total_equity_area = 0.0
|
|
|
|
for idx, prop in enumerate(properties, start=1):
|
|
# 按结束日期或当前日期选取有效管理信息
|
|
target_date = end_dt or datetime.date.today()
|
|
valid_info = prop.manage_information_ids.filtered(
|
|
lambda info: info.start_time <= target_date and (not info.end_date or info.end_date >= target_date)
|
|
)[:1]
|
|
|
|
# 若指定了日期范围但无有效管理信息,则跳过
|
|
if (date_start or date_end) and not valid_info:
|
|
continue
|
|
|
|
management_area = valid_info.management_area if valid_info else prop.management_area
|
|
rent_area = valid_info.rent_area if valid_info else prop.rent_area
|
|
company = valid_info.company_id if valid_info else prop.company_id
|
|
purpose = valid_info.purpose_id if valid_info else prop.purpose_id
|
|
message_standard = prop.message_standard_id # 信息行无管理费标准字段,直接取物业字段
|
|
|
|
total_rent_area += rent_area or 0.0
|
|
total_equity_area += prop.equity_area or 0.0
|
|
|
|
rows.append({
|
|
"序号": idx,
|
|
"物业id": prop.id,
|
|
"产权证号": prop.title_deed or "",
|
|
"物业名称": prop.name or "",
|
|
"可租面积": round(rent_area or 0.0, 4),
|
|
"产权面积": round(prop.equity_area or 0.0, 4),
|
|
"用途": purpose.name if purpose else "",
|
|
"管理费标准": message_standard.name if message_standard else "",
|
|
})
|
|
|
|
return {
|
|
"rows": rows,
|
|
"summary": {
|
|
"序号": False,
|
|
"物业id": "合计",
|
|
"产权证号": False,
|
|
"物业名称": False,
|
|
"可租面积": round(total_rent_area, 4),
|
|
"产权面积": round(total_equity_area, 4),
|
|
"用途": False,
|
|
"管理费标准": False,
|
|
}
|
|
}
|
|
|