From d375104e5e8d0fc04580ee06336f0fb15a175ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= <9664676+pengyuthon@user.noreply.gitee.com> Date: Fri, 24 Oct 2025 18:45:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_report/models/ledger_report.py | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/yuthon_report/models/ledger_report.py b/yuthon_report/models/ledger_report.py index 0db9b70ba..b124a7341 100644 --- a/yuthon_report/models/ledger_report.py +++ b/yuthon_report/models/ledger_report.py @@ -18,10 +18,17 @@ class YuthonProperty(models.Model): if params.get("date_start"): date_start = datetime.datetime.fromisoformat(params.get("date_start")).date() domain.append(("effective_date", ">=", date_start)) + else: + date_start = None if params.get("date_end"): date_end = datetime.datetime.fromisoformat(params.get("date_start")).date() - domain.append(("end_date", "<=", date_end)) - + domain.append([ + "|", + ("end_date", "<=", date_end), + ("end_date", "=", False) + ]) + else: + date_end = None condition = params.get('condition',False) partner_id = params.get('partner_id',False) @@ -48,22 +55,24 @@ class YuthonProperty(models.Model): result = [] for p in properties: - # 1. 筛选符合日期范围的合同:property_contract_ids中满足周期交集的记录 filtered_contracts = p.property_contract_ids.filtered( lambda contract: contract.start_time and - (not contract.end_time or contract.end_time >= date_start) and - contract.start_time <= (date_end or datetime.max.date()) + (not date_start or not contract.end_date or contract.end_date >= date_start) and + (not date_end or contract.start_time <= date_end) ) - # 2. 处理筛选后的合同 - target_contract = filtered_contracts if filtered_contracts else False + target_contract = False + if filtered_contracts: + sorted_contracts = filtered_contracts.sorted(key=lambda c: c.start_time) + target_contract = sorted_contracts[0].lease_contract_id + # 3. 获取合同信息 rent_company = target_contract.rent_company if target_contract else "" lessee_id = target_contract.lessee_id.name if (target_contract and target_contract.lessee_id) else "" property_name = target_contract.property_name if target_contract else "" contact = target_contract.lessee_id.contact if (target_contract and target_contract.lessee_id) else "" - rental_purposes = target_contract.rental_purposes if target_contract else "" + rental_purposes = target_contract.rental_purposes.name if target_contract else "" contract_code = target_contract.contract_code if target_contract else "" total_area = target_contract.total_area if target_contract else 0.0 first_year_rent = target_contract.first_year_rent if target_contract else 0.0 @@ -87,7 +96,7 @@ class YuthonProperty(models.Model): if target_contract: lease_line = self.env['property.lease.contract.line'].search([ ('address_id', '=', p.id), # 按资产ID匹配明细行 - ('lease_contract_id', '=', target_contract.id) # 按目标合同匹配 + ('lease_id', '=', target_contract.id) # 按目标合同匹配 ], limit=1) evaluate_unit_price = lease_line.evaluate_unit_price if lease_line else 0.0 @@ -105,7 +114,7 @@ class YuthonProperty(models.Model): "出租地址": property_name, "联系人": contact, "出租用途": rental_purposes, - "审批情况": p.approval_status or "", + "审批情况": "已审批", "租赁合同号": contract_code, "出租面积": total_area, "评估价(元/m² •月)": evaluate_unit_price,