@@ -124,7 +124,6 @@ class PropertyManagement(models.Model):
|
||||
new_contract = old_contract.copy({
|
||||
'contract_code': new_code,
|
||||
'contract_source_id': old_contract.id,
|
||||
'condition': 'new', # 进入合同审批列表
|
||||
})
|
||||
new_contract_map[old_contract.id] = new_contract.id
|
||||
|
||||
@@ -176,29 +175,52 @@ class PropertyManagement(models.Model):
|
||||
if prev_info.yuthon_property_id.company_id.rent_account == self.company_id.rent_account:
|
||||
return
|
||||
|
||||
# 找现有合同
|
||||
lease_line = self.env['property.lease.contract.line'].search([
|
||||
# 找现有合同(实际开始<生效日期,取最近的那份)
|
||||
lease_lines = self.env['property.lease.contract.line'].search([
|
||||
('address_id', '=', manage_line.property_id.id),
|
||||
('lease_id', '!=', False),
|
||||
('lease_id.contact_state', '=', 'ing'),
|
||||
('lease_id.actual_end_time', '>=', self.start_time),
|
||||
], limit=1)
|
||||
if not lease_line:
|
||||
if not lease_lines:
|
||||
return
|
||||
|
||||
old_contract = lease_line.lease_id
|
||||
# 勾了新合同 → 直接用新合同ID;没勾 → 用现有合同
|
||||
new_cid = new_contract_map.get(old_contract.id)
|
||||
current_contract = self.env['property.lease.contract'].browse(new_cid) if new_cid else old_contract
|
||||
for lease_line in lease_lines:
|
||||
old_contract = lease_line.lease_id
|
||||
# 勾了新合同 → 直接用新合同ID;没勾 → 用现有合同
|
||||
new_cid = new_contract_map.get(old_contract.id)
|
||||
current_contract = self.env['property.lease.contract'].browse(new_cid) if new_cid else old_contract
|
||||
|
||||
# 没有原合同 → original_contract 就是当前合同本身,只生成 bills.list
|
||||
if not current_contract.contract_source_id:
|
||||
original_contract = current_contract
|
||||
deposit_type = self.env['yuthon.management.type'].search(
|
||||
[('name', '=', '押金')], limit=1)
|
||||
if not deposit_type:
|
||||
deposit_type = self.env['yuthon.management.type'].create({'name': '押金'})
|
||||
|
||||
if original_contract and original_contract.deposit:
|
||||
existing_bill = self.env['property.bills.list'].search([
|
||||
('contract_id', '=', original_contract.id),
|
||||
('management_type_id', '=', deposit_type.id),
|
||||
], limit=1)
|
||||
if not existing_bill:
|
||||
self.env['property.bills.list'].create({
|
||||
'contract_id': original_contract.id,
|
||||
'amount': original_contract.deposit,
|
||||
'due_date': self.start_time,
|
||||
'management_type_id': deposit_type.id,
|
||||
})
|
||||
continue
|
||||
|
||||
original_contract = current_contract.contract_source_id
|
||||
|
||||
# 没有原合同 → original_contract 就是当前合同本身,只生成 bills.list
|
||||
if not current_contract.contract_source_id:
|
||||
original_contract = current_contract
|
||||
# 获取或创建"押金"管理类型
|
||||
deposit_type = self.env['yuthon.management.type'].search(
|
||||
[('name', '=', '押金')], limit=1)
|
||||
if not deposit_type:
|
||||
deposit_type = self.env['yuthon.management.type'].create({'name': '押金'})
|
||||
|
||||
# ① 原合同:创建应付账单 property.bills.list
|
||||
if original_contract and original_contract.deposit:
|
||||
existing_bill = self.env['property.bills.list'].search([
|
||||
('contract_id', '=', original_contract.id),
|
||||
@@ -211,44 +233,20 @@ class PropertyManagement(models.Model):
|
||||
'due_date': self.start_time,
|
||||
'management_type_id': deposit_type.id,
|
||||
})
|
||||
return
|
||||
|
||||
original_contract = current_contract.contract_source_id
|
||||
|
||||
# 获取或创建"押金"管理类型
|
||||
deposit_type = self.env['yuthon.management.type'].search(
|
||||
[('name', '=', '押金')], limit=1)
|
||||
if not deposit_type:
|
||||
deposit_type = self.env['yuthon.management.type'].create({'name': '押金'})
|
||||
|
||||
# ① 原合同:创建应付账单 property.bills.list
|
||||
if original_contract and original_contract.deposit:
|
||||
existing_bill = self.env['property.bills.list'].search([
|
||||
('contract_id', '=', original_contract.id),
|
||||
('management_type_id', '=', deposit_type.id),
|
||||
], limit=1)
|
||||
if not existing_bill:
|
||||
self.env['property.bills.list'].create({
|
||||
'contract_id': original_contract.id,
|
||||
'amount': original_contract.deposit,
|
||||
'due_date': self.start_time,
|
||||
'management_type_id': deposit_type.id,
|
||||
})
|
||||
|
||||
# ② 当前合同:查找或创建押金应收 property.accounts.receivable
|
||||
if current_contract and current_contract.deposit:
|
||||
existing_receivable = self.env['property.accounts.receivable'].search([
|
||||
('contract_id', '=', current_contract.id),
|
||||
('management_type_id', '=', deposit_type.id),
|
||||
], limit=1)
|
||||
if not existing_receivable:
|
||||
self.env['property.accounts.receivable'].create({
|
||||
'contract_id': current_contract.id,
|
||||
'due_date': self.start_time,
|
||||
'original_amount': current_contract.deposit,
|
||||
'management_type_id': deposit_type.id,
|
||||
'deposit_state': 'unpaid'
|
||||
})
|
||||
# ② 当前合同:查找或创建押金应收 property.accounts.receivable
|
||||
if current_contract and current_contract.deposit:
|
||||
existing_receivable = self.env['property.accounts.receivable'].search([
|
||||
('contract_id', '=', current_contract.id),
|
||||
('management_type_id', '=', deposit_type.id),
|
||||
], limit=1)
|
||||
if not existing_receivable:
|
||||
self.env['property.accounts.receivable'].create({
|
||||
'contract_id': current_contract.id,
|
||||
'due_date': self.start_time,
|
||||
'original_amount': current_contract.deposit,
|
||||
'management_type_id': deposit_type.id,
|
||||
})
|
||||
|
||||
def approval_end(self):
|
||||
for record in self:
|
||||
@@ -266,6 +264,7 @@ class PropertyManagement(models.Model):
|
||||
lease_contract = self.env['property.lease.contract.line'].search(
|
||||
[('address_id', '=', manage_line.property_id.id),
|
||||
('lease_id', '!=', False),
|
||||
('lease_id.actual_end_time', '>=', self.start_time),
|
||||
], limit=1)
|
||||
if lease_contract:
|
||||
contract_actual_end = lease_contract.lease_id.actual_end_time
|
||||
|
||||
Reference in New Issue
Block a user