@@ -26,9 +26,10 @@ class LeasedAreaReport(models.Model):
|
||||
- actual_end_time 为空 → 查不到(数据不完整)
|
||||
3. 物业已租面积:合同下所有物业的 property_area 之和(即 contract.total_area)
|
||||
4. 合同已租面积:contract.total_area(合同总面积)
|
||||
5. 产权证号、产权地址从第一个物业的 title.information.line 取
|
||||
5. 实际开始时间、实际结束时间取自 contract.actual_start_time / actual_end_time
|
||||
6. 片区管理员从第一个物业的 manage.information.line 取(按查询日期匹配)
|
||||
7. 支持按物业名称(property_id)、承租方(lessee_id)、合同编号(contract_id)搜索
|
||||
8. 按物业筛选时,只保留包含该物业的合同,但合同仍显示全部物业信息(物业名称、面积均累加全部物业)
|
||||
"""
|
||||
|
||||
# ========== 一、参数解析 ==========
|
||||
@@ -74,15 +75,20 @@ class LeasedAreaReport(models.Model):
|
||||
# 合同编号过滤
|
||||
if contract_id:
|
||||
contract_domain.append(('id', '=', int(contract_id)))
|
||||
# 物业过滤:只保留包含该物业的合同,但不过滤合同行(合同仍显示全部物业)
|
||||
if property_id:
|
||||
prop_contract_ids = self.env['property.lease.contract.line'].sudo().search([
|
||||
('address_id', '=', int(property_id))
|
||||
]).mapped('lease_id.id')
|
||||
contract_domain.append(('id', 'in', prop_contract_ids))
|
||||
|
||||
# 先查出基础符合条件的合同(不过滤时间,后面在循环中精确判断)
|
||||
contracts = self.env['property.lease.contract'].sudo().search(contract_domain)
|
||||
|
||||
# ========== 四、查询合同下的所有物业明细行 ==========
|
||||
# 用于:物业名称过滤、property_id 过滤、计算物业已租面积
|
||||
# 用于:物业名称、计算物业已租面积
|
||||
# 注意:不对 contract.line 做 property_id 过滤,合同仍显示全部物业信息
|
||||
line_domain = [('lease_id', 'in', contracts.ids)] if contracts else [('id', '=', -1)]
|
||||
if property_id:
|
||||
line_domain.append(('address_id', '=', int(property_id)))
|
||||
|
||||
contract_lines = self.env['property.lease.contract.line'].sudo().search(line_domain)
|
||||
|
||||
@@ -229,28 +235,12 @@ class LeasedAreaReport(models.Model):
|
||||
if not matched:
|
||||
continue
|
||||
|
||||
# --- 6.5 取产权信息(取第一个物业的产权证号、产权地址) ---
|
||||
title_certificate = ""
|
||||
property_address = ""
|
||||
if first_property and first_property.title_information_ids:
|
||||
valid_titles = first_property.title_information_ids
|
||||
if query_date:
|
||||
valid_titles = valid_titles.filtered(
|
||||
lambda t: t.start_time and t.start_time <= query_date and
|
||||
(not t.end_date or t.end_date >= query_date)
|
||||
)
|
||||
if valid_titles:
|
||||
latest_title = valid_titles.sorted('start_time', reverse=True)[0]
|
||||
title_certificate = latest_title.title_certificate or ""
|
||||
if latest_title.property_message_id:
|
||||
property_address = latest_title.property_message_id.name or ""
|
||||
|
||||
# --- 6.6 片区管理员(取第一个物业的片区管理员) ---
|
||||
# --- 6.5 片区管理员(取第一个物业的片区管理员) ---
|
||||
admin_display = ""
|
||||
if manage_line and manage_line.precinct_id:
|
||||
admin_display = manage_line.precinct_id.display_name or ""
|
||||
|
||||
# --- 6.7 物业已租面积:该合同下所有物业 property_area 之和 ---
|
||||
# --- 6.6 物业已租面积:该合同下所有物业 property_area 之和 ---
|
||||
# 即 contract.total_area,但逐个计算更可靠
|
||||
property_area_sum = sum((cl.property_area or 0.0) for cl in lines)
|
||||
# 合同已租面积
|
||||
@@ -270,7 +260,7 @@ class LeasedAreaReport(models.Model):
|
||||
for pid in property_ids_in_row:
|
||||
seen_property_ids.add(pid)
|
||||
|
||||
# --- 6.8 物业名称和物业ID:列出该合同下所有物业 ---
|
||||
# --- 6.7 物业名称和物业ID:列出该合同下所有物业 ---
|
||||
property_names = []
|
||||
property_ids_strs = []
|
||||
for cl in lines:
|
||||
@@ -290,7 +280,7 @@ class LeasedAreaReport(models.Model):
|
||||
else:
|
||||
property_name_value = display_property_name
|
||||
|
||||
# --- 6.9 构建行数据(物业名称、合同编号、承租方支持穿透) ---
|
||||
# --- 6.8 构建行数据(物业名称、合同编号、承租方支持穿透) ---
|
||||
# 实际起止时间格式化
|
||||
actual_start = contract.actual_start_time
|
||||
if actual_start:
|
||||
|
||||
Reference in New Issue
Block a user