From b3185780a8224df3cada59a7a838518cc3d14dd5 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: Tue, 23 Dec 2025 18:09:00 +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_property/models/yuthon_property.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/yuthon_property/models/yuthon_property.py b/yuthon_property/models/yuthon_property.py index 579a022cb..951897e76 100644 --- a/yuthon_property/models/yuthon_property.py +++ b/yuthon_property/models/yuthon_property.py @@ -100,12 +100,24 @@ class YuthonProperty(models.Model): today = date.today() current_year = today.year current_month = today.month - rentable_properties = self.search([('purpose_id.name', '=', '可租')]) + rentable_properties = self.env["yuthon.property"].browse( + self._context.get('active_ids', self._context.get('active_id'))) + # rentable_properties = self.search([('purpose_id.name', '=', '可租')]) for prop in rentable_properties: - lease_id = self.env['property.lease.contract.line'].search([ + contract_lines = self.env['property.lease.contract.line'].search([ ('address_id', '=', prop.id), ('lease_id.contact_state', '=', 'ing') - ], limit=1) + ]) + if contract_lines: + sorted_lines = sorted( + contract_lines, + key=lambda line: line.lease_id.actual_end_time, + reverse=True + ) + lease_id = sorted_lines[0] + else: + lease_id = self.env['property.lease.contract.line'] + if not lease_id: prop.write({'property_state': 'vacant'}) continue