添加功能
This commit is contained in:
@@ -933,13 +933,25 @@ class PropertyLeaseContract(models.Model):
|
||||
# 续租审批应退押金逻辑
|
||||
if self.contract_id and self.contract_id.deposit and self.contract_type == 'lease_renewal':
|
||||
management_type_id = self.env['yuthon.management.type'].search([('name', '=', '押金')], limit=1)
|
||||
workflow_record_id = self.env["soong.workflow.record"].search(
|
||||
[("res_model", "=", self._name), ("res_id", "=", self.id)])
|
||||
contract_end_date = self.contract_id.term_end_time
|
||||
# 限制:原合同存在未对账的应收账单(未收>0 且未作废)则不能结束
|
||||
un_reconciled = self.env['property.accounts.receivable'].search([
|
||||
('due_date', '<=', contract_end_date),
|
||||
('contract_id', '=', self.contract_id.id),
|
||||
('is_invalid', '=', False),
|
||||
('submitted', '>', 0.0),
|
||||
]).filtered(lambda r: not r.is_reconciliation)
|
||||
if un_reconciled:
|
||||
raise UserError("该合同下存在未对账的应收单,无法结束")
|
||||
# 旧合同 -> 已结清
|
||||
self.contract_id.contact_state = 'settle'
|
||||
bills_list = self.env['property.bills.list'].search([
|
||||
('contract_id', '=', self.contract_id.id,)
|
||||
])
|
||||
workflow_record_id = self.env["soong.workflow.record"].search(
|
||||
[("res_model", "=", self._name), ("res_id", "=", self.id)])
|
||||
if not bills_list:
|
||||
self.env['property.bills.list'].create({
|
||||
bills_list = self.env['property.bills.list'].create({
|
||||
'lessor_id': self.contract_id.lessor_id.id,
|
||||
'due_date': self.contract_id.actual_end_time + timedelta(days=1), # 原合同
|
||||
'management_type_id': management_type_id.id,
|
||||
@@ -948,49 +960,40 @@ class PropertyLeaseContract(models.Model):
|
||||
'remake': '续签退押',
|
||||
'workflow_record_id': workflow_record_id.id,
|
||||
})
|
||||
bank_id = self.env['property.bank.statements'].search([
|
||||
('name_account', '=', self.contract_id.lessee_id.name),
|
||||
('contract_ids', 'in', self.id),
|
||||
('remake', '=', '续签退押'),
|
||||
])
|
||||
if not bank_id:
|
||||
lessor_id = self.contract_id.lessor_id # 出租方
|
||||
tenant_line = self.env['property.tenant.line'].search([
|
||||
('tenant_id', '=', self.lessee_id.id),
|
||||
('lease_contract_id', '=', self.id),
|
||||
], limit=1)
|
||||
if not tenant_line:
|
||||
self.env['property.tenant.line'].create({
|
||||
'tenant_id': self.lessee_id.id,
|
||||
'lease_contract_id': self.id,
|
||||
})
|
||||
company_id = self.env['res.company'].search([('name', '=', '集团本部')], limit=1)
|
||||
if lessor_id.referred in ['天河投资', '天投城建']:
|
||||
company_id = self.env['res.company'].search([('name', '=', '集团本部')], limit=1)
|
||||
elif lessor_id.referred in ['天河物管']:
|
||||
company_id = self.env['res.company'].browse(3)
|
||||
elif lessor_id.referred in ['天河粮储']:
|
||||
company_id = self.env['res.company'].search([('name', '=', '天河粮储')], limit=1)
|
||||
bank_accounts = self.env['property.bank.line'].search([
|
||||
('tenant_id', '=', self.lessee_id.id)
|
||||
]).mapped('bank')
|
||||
filtered_accounts = [acc for acc in bank_accounts if acc]
|
||||
bank_accounts = filtered_accounts[0] if filtered_accounts else None
|
||||
end_date = self.contract_id.actual_end_time + timedelta(days=1)
|
||||
start_time = f"{end_date} 09:00:00"
|
||||
bank_id = self.env['property.bank.statements'].sudo().create({
|
||||
'start_time': start_time,
|
||||
'name': bank_accounts,
|
||||
# 生成后:应付日期/实付日期 = 原合同合同结束日期,实付 = 应付
|
||||
bills_list.write({
|
||||
'due_date': contract_end_date,
|
||||
'actual_date': contract_end_date,
|
||||
'amount_actual': self.contract_id.deposit,
|
||||
'pay_state': 'paid',
|
||||
})
|
||||
# 原合同押金应收 -> 已退(退款日期 = 应付账单实付日期)
|
||||
self.env['property.accounts.receivable'].search([
|
||||
('contract_id', '=', self.contract_id.id),
|
||||
('management_type_id.name', '=', '押金'),
|
||||
]).write({
|
||||
'deposit_state': 'yes',
|
||||
'has_date': bills_list[:1].actual_date,
|
||||
})
|
||||
# 新合同押金应收 -> 已收、已对账(应收开始 = 新合同实际开始时间)
|
||||
# 重复判断:新合同若已存在押金应收账单则不重复创建
|
||||
new_deposit = self.env['property.accounts.receivable'].search([
|
||||
('contract_id', '=', self.id),
|
||||
('management_type_id.name', '=', '押金'),
|
||||
], limit=1)
|
||||
if not new_deposit:
|
||||
self.env['property.accounts.receivable'].create({
|
||||
'contract_id': self.id,
|
||||
'management_type_id': management_type_id.id,
|
||||
'original_amount': self.contract_id.deposit,
|
||||
'name_account': self.contract_id.lessee_id.name,
|
||||
'remake': '续签退押',
|
||||
'lending_direction': 'loan',
|
||||
'workflow_record_id': workflow_record_id.id,
|
||||
'company_id': company_id.id,
|
||||
'your_own_unit': lessor_id.referred,
|
||||
'your_own_account': lessor_id.rent_account,
|
||||
'delivered1': self.contract_id.deposit,
|
||||
'deposit_state': 'paid',
|
||||
'is_reconciliation': True,
|
||||
'payout_date': self.actual_start_time,
|
||||
'due_date': self.actual_start_time or self.term_start_time,
|
||||
'lessee_id': self.lessee_id.id,
|
||||
'property_name': self.property_name,
|
||||
})
|
||||
bank_id._compute_property_employee_id()
|
||||
|
||||
if self.term_start_time <= current_date <= self.term_end_time:
|
||||
new_contact_state = 'ing'
|
||||
|
||||
Reference in New Issue
Block a user