!9944 Merge branch 'dev' of <a href="https://gitee.com/jinan-pengyusen-data/gzth">https://gitee.com/jinan-pengyusen-data/gzth</a> into dev_wang
Merge pull request !9944 from 李鹏宇/dev_wang
This commit is contained in:
@@ -4,30 +4,44 @@ from odoo import api, models
|
||||
|
||||
|
||||
class ManagementAreaReport(models.Model):
|
||||
_inherit = 'yuthon.property'
|
||||
_name = 'management.area.report'
|
||||
_description = '管理面积报表'
|
||||
_auto = False
|
||||
|
||||
@api.model
|
||||
def get_management_area_report(self, params):
|
||||
"""管理面积报表数据源。"""
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
_logger.warning('=== 管理面积报表 params: %s', params)
|
||||
domain = []
|
||||
|
||||
keyword = params.get("keyword")
|
||||
if keyword:
|
||||
domain += [
|
||||
'|', '|',
|
||||
('name', 'ilike', keyword),
|
||||
('title_deed', 'ilike', keyword),
|
||||
('code', 'ilike', keyword),
|
||||
]
|
||||
|
||||
# 单日期模式,前端传 date_start
|
||||
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
|
||||
# 兼容单日期和日期范围,优先取 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:
|
||||
@@ -35,54 +49,88 @@ class ManagementAreaReport(models.Model):
|
||||
if company_id:
|
||||
domain.append(('company_id', '=', company_id))
|
||||
|
||||
properties = self.search(domain, limit=2000)
|
||||
# 查询管理信息明细行(过滤掉没有关联物业的无效行)
|
||||
domain.append(('yuthon_property_id', '!=', False))
|
||||
_logger.warning('=== 管理面积报表 domain: %s, query_date_obj: %s', domain, query_date_obj)
|
||||
manage_lines = self.env['manage.information.line'].search(domain)
|
||||
_logger.warning('=== 管理面积报表 manage_lines count: %s', len(manage_lines))
|
||||
# 如果有数据,打印第一条看看字段内容
|
||||
if manage_lines:
|
||||
first = manage_lines[0]
|
||||
_logger.warning('=== 第一条 end_date=%s, yuthon_property_id=%s', first.end_date, first.yuthon_property_id)
|
||||
|
||||
rows = []
|
||||
total_management_area = 0.0
|
||||
total_rent_area = 0.0
|
||||
total_equity_area = 0.0
|
||||
total_total_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:
|
||||
for idx, line in enumerate(manage_lines, start=1):
|
||||
# 获取物业信息
|
||||
property_id = line.yuthon_property_id
|
||||
if not property_id:
|
||||
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 # 信息行无管理费标准字段,直接取物业字段
|
||||
# 搜索关键词过滤
|
||||
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
|
||||
|
||||
total_rent_area += rent_area or 0.0
|
||||
total_equity_area += prop.equity_area or 0.0
|
||||
# 获取管理类型
|
||||
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": 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 "",
|
||||
"物业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,
|
||||
"_debug_rows_count": len(rows),
|
||||
"summary": {
|
||||
"序号": False,
|
||||
"物业id": "合计",
|
||||
"产权证号": False,
|
||||
"物业名称": False,
|
||||
"失效日期": False,
|
||||
"管理类型": False,
|
||||
"管理面积": round(total_management_area, 4),
|
||||
"可租面积": round(total_rent_area, 4),
|
||||
"产权面积": round(total_equity_area, 4),
|
||||
"用途": False,
|
||||
"管理费标准": False,
|
||||
"合同编号": False,
|
||||
"总面积": round(total_total_area, 4),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,17 +8,20 @@
|
||||
{
|
||||
"sideBar": true,
|
||||
"report_config": {
|
||||
"model": "yuthon.property",
|
||||
"model": "management.area.report",
|
||||
"method": "get_management_area_report",
|
||||
"dateMode": "single",
|
||||
"columns": [
|
||||
{"headerName": "序号", "field": "序号", "width": 45, "flex": 0, "pinned": "left"},
|
||||
{"headerName": "物业id", "field": "物业id", "flex": 0.8},
|
||||
{"headerName": "产权证号", "field": "产权证号", "flex": 1.2},
|
||||
{"headerName": "物业名称", "field": "物业名称", "flex": 1.8},
|
||||
{"headerName": "失效日期", "field": "失效日期", "flex": 1.2},
|
||||
{"headerName": "管理类型", "field": "管理类型", "flex": 1},
|
||||
{"headerName": "管理面积", "field": "管理面积", "flex": 1, "type": "number"},
|
||||
{"headerName": "可租面积", "field": "可租面积", "flex": 1, "type": "number"},
|
||||
{"headerName": "产权面积", "field": "产权面积", "flex": 1, "type": "number"},
|
||||
{"headerName": "用途", "field": "用途", "flex": 1},
|
||||
{"headerName": "管理费标准", "field": "管理费标准", "flex": 1}
|
||||
{"headerName": "合同编号", "field": "合同编号", "flex": 1.5},
|
||||
{"headerName": "总面积", "field": "总面积", "flex": 1, "type": "number"}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user