127 lines
4.6 KiB
Python
127 lines
4.6 KiB
Python
import datetime
|
|
|
|
from odoo import api, models
|
|
|
|
|
|
class ManagementAreaReport(models.Model):
|
|
_name = 'management.area.report'
|
|
_description = '管理面积报表'
|
|
_auto = False
|
|
|
|
@api.model
|
|
def get_management_area_report(self, params):
|
|
"""管理面积报表数据源。"""
|
|
domain = []
|
|
|
|
keyword = params.get("keyword")
|
|
# 单日期模式,前端传 date_start
|
|
date_start = params.get("date_start")
|
|
date_end = params.get("date_end")
|
|
# 兼容单日期和日期范围,优先取 date_start
|
|
query_date_str = date_start or date_end
|
|
|
|
condition = params.get('condition')
|
|
partner_id = params.get('partner_id')
|
|
company_id = params.get('company_id')
|
|
|
|
# 构建管理信息明细行的查询域
|
|
domain = []
|
|
query_date_obj = None
|
|
|
|
# 处理日期过滤:失效日期晚于查询日期,或没有失效日期
|
|
if query_date_str:
|
|
try:
|
|
# 将带时间后缀的格式截断,如 "2024-11-01 00:00:00" -> "2024-11-01"
|
|
query_date_obj = datetime.datetime.fromisoformat(query_date_str.split(' ')[0]).date()
|
|
domain += [
|
|
'|', ('end_date', '>=', query_date_obj), ('end_date', '=', False)
|
|
]
|
|
except Exception:
|
|
pass
|
|
|
|
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))
|
|
|
|
# 查询管理信息明细行(过滤掉没有关联物业的无效行)
|
|
domain.append(('yuthon_property_id', '!=', False))
|
|
manage_lines = self.env['manage.information.line'].search(domain)
|
|
|
|
rows = []
|
|
total_management_area = 0.0
|
|
total_rent_area = 0.0
|
|
total_total_area = 0.0
|
|
|
|
for idx, line in enumerate(manage_lines, start=1):
|
|
# 获取物业信息
|
|
property_id = line.yuthon_property_id
|
|
if not property_id:
|
|
continue
|
|
|
|
# 搜索关键词过滤
|
|
if keyword:
|
|
if not (
|
|
(property_id.name and keyword in property_id.name) or
|
|
(property_id.title_deed and keyword in property_id.title_deed) or
|
|
(property_id.code and keyword in property_id.code)
|
|
):
|
|
continue
|
|
|
|
# 获取管理类型
|
|
management_type = line.purpose_id.name if line.purpose_id else ""
|
|
|
|
# 获取合同编号和总面积
|
|
contract_code = ""
|
|
total_area = 0.0
|
|
contract_domain = [('yuthon_property_id', '=', property_id.id)]
|
|
|
|
if query_date_str:
|
|
contract_domain += [
|
|
'|', ('end_date', '>=', query_date_obj), ('end_date', '=', False)
|
|
]
|
|
|
|
contract_lines = self.env['property.contract.line'].search(contract_domain, limit=1)
|
|
if contract_lines:
|
|
lease_contract = contract_lines.lease_contract_id
|
|
if lease_contract:
|
|
contract_code = lease_contract.contract_code or ""
|
|
total_area = lease_contract.total_area or 0.0
|
|
|
|
# 累计面积
|
|
total_management_area += line.management_area or 0.0
|
|
total_rent_area += line.rent_area or 0.0
|
|
total_total_area += total_area
|
|
|
|
rows.append({
|
|
"序号": idx,
|
|
"物业id": property_id.id,
|
|
"产权证号": property_id.title_deed or "",
|
|
"物业名称": property_id.name or "",
|
|
"失效日期": line.end_date.strftime("%Y-%m-%d") if line.end_date else "",
|
|
"管理类型": management_type,
|
|
"管理面积": round(line.management_area or 0.0, 4),
|
|
"可租面积": round(line.rent_area or 0.0, 4),
|
|
"合同编号": contract_code,
|
|
"总面积": round(total_area, 4),
|
|
})
|
|
|
|
return {
|
|
"rows": rows,
|
|
"summary": {
|
|
"序号": False,
|
|
"物业id": "合计",
|
|
"产权证号": False,
|
|
"物业名称": False,
|
|
"失效日期": False,
|
|
"管理类型": False,
|
|
"管理面积": round(total_management_area, 4),
|
|
"可租面积": round(total_rent_area, 4),
|
|
"合同编号": False,
|
|
"总面积": round(total_total_area, 4),
|
|
}
|
|
}
|
|
|