From 17400a588fe26d089a722182b71a1171c167a1c4 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, 17 Oct 2025 14:57:50 +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 --- .../models/property_lease_contract.py | 50 +++++++++++++++++++ .../wizard/property_rental_wizard.py | 6 ++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/yuthon_property_approval/models/property_lease_contract.py b/yuthon_property_approval/models/property_lease_contract.py index 9ce9555ea..cb3ea1b00 100644 --- a/yuthon_property_approval/models/property_lease_contract.py +++ b/yuthon_property_approval/models/property_lease_contract.py @@ -1365,6 +1365,56 @@ class PropertyLeaseContract(models.Model): f"合同编号必须唯一!已存在编号:{existing.contract_code}", )) + @api.onchange("contract_sort") + def _onchange_contract_sort(self): + if not self.contract_sort: + return + + current_year = fields.Date.today().year + # 定义各类型前缀和编号长度 + type_config = { + 'guanggao': {'prefix': '广', 'length': 3}, # 广告位:3位数字 + 'guanzi': {'prefix': '管', 'length': 3}, # 管子间:3位数字 + 'property': {'prefix': '租', 'length': 4}, # 物业:4位数字 + 'room': {'prefix': '租', 'length': 4}, # 机房:4位数字 + 'base_station': {'prefix': '租', 'length': 4}, # 基站:4位数字 + 'other': {'prefix': '租', 'length': 4} # 其他:4位数字 + } + + config = type_config.get(self.contract_sort) + if not config: + return + prefix = config['prefix'] + num_length = config['length'] + + # 正则模式:前缀 + (年份) + 固定长度数字(如 租(2025)0001 或 广(2025)001) + patterns = [ + re.compile(rf"^{re.escape(prefix)}\({current_year}\)(\d{{{num_length}}})$"), + re.compile(rf"^{re.escape(prefix)}({current_year})(\d{{{num_length}}})$") + ] + + max_num = 0 + same_type_contracts = self.env['property.lease.contract'].search([ + ('term_start_time', '>=', date(2025, 10, 1)), + ('id', '!=', self.id.origin) + ]) + for contract in same_type_contracts: + if not contract.contract_code: + continue + # 检查是否匹配两种格式中的任意一种 + for pattern in patterns: + match = pattern.match(contract.contract_code) + if match: + # 提取数字部分并比较 + num = int(match.group(1)) + if num > max_num: + max_num = num + break + + new_num = max_num + 1 + formatted_num = f"{new_num:0{num_length}d}" + self.contract_code = f"{prefix}({current_year}){formatted_num}" + def _normalize_contract_code(self, code): """将合同编号中的括号统一为中文括号""" if not code: diff --git a/yuthon_property_approval/wizard/property_rental_wizard.py b/yuthon_property_approval/wizard/property_rental_wizard.py index aec023a59..d938842d0 100644 --- a/yuthon_property_approval/wizard/property_rental_wizard.py +++ b/yuthon_property_approval/wizard/property_rental_wizard.py @@ -104,6 +104,7 @@ class PropertyRentalWizard(models.Model): ('due_date', '>=', first_day_of_month), ('due_date', '<=', last_day_of_month) ]) + matched_info = self.env['manage.information.line'] if record.contract_sort in ['guanggao','guanzi']: original_amount = rent_amount else: @@ -126,11 +127,12 @@ class PropertyRentalWizard(models.Model): is_special_contract = record.contract_sort in ['guanggao', 'guanzi'] has_valid_property_info = property_id.manage_information_ids and property_id.message_standard_id if (not is_special_contract and has_valid_property_info) or is_special_contract: + area_value = matched_info.management_area if matched_info else 0 if not management_id: self.sudo().env["property.management.list"].create({ "contract_id": record.id, "property_id": property_id.id, - "area":matched_info.management_area, + "area":area_value, 'original_amount':original_amount, 'message_standard_id': property_id.message_standard_id.id, 'lessee_id': record.lessee_id.id, @@ -140,7 +142,7 @@ class PropertyRentalWizard(models.Model): management_id.write({ "contract_id": record.id, "property_id": property_id.id, - "area": matched_info.management_area, + "area": area_value, 'original_amount': original_amount, 'message_standard_id': property_id.message_standard_id.id, 'lessee_id': record.lessee_id.id,