添加功能
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user