diff --git a/yuthon_property_approval/models/property_lease_contract.py b/yuthon_property_approval/models/property_lease_contract.py index 9742b8345..49990cdaa 100644 --- a/yuthon_property_approval/models/property_lease_contract.py +++ b/yuthon_property_approval/models/property_lease_contract.py @@ -846,30 +846,64 @@ class PropertyLeaseContract(models.Model): def end_approval(self): current_date = date.today() # 续租审批应退押金逻辑 - if self.contract_id and self.self.contract_id.deposit: + 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) 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({ - 'due_date': fields.Date.today(), + 'due_date': self.contract_id.actual_end_time + timedelta(days=1), # 原合同 'management_type_id': management_type_id.id, 'amount': self.contract_id.deposit, 'contract_id': self.contract_id.id, + 'remake': '续签退押', + 'workflow_record_id': workflow_record_id.id, }) - bank_id = self.env['property.bank.statements'].search([ ('name_account', '=', self.contract_id.lessee_id.name), - ('remake', '=', '应退押金'), + ('contract_ids', 'in', self.id), + ('remake', '=', '续签退押'), ]) if not bank_id: - self.env['property.bank.statements'].sudo().create({ - 'start_time': fields.Datetime.now() + timedelta(hours=8), + 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'].search([('name', '=', '天河物管')], limit=1) + 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') + bank_accounts = [acc for acc in bank_accounts if acc][0] + 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, 'original_amount': self.contract_id.deposit, 'name_account': self.contract_id.lessee_id.name, - 'remake': '应退押金', + '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, }) + bank_id._compute_property_employee_id() if self.term_start_time <= current_date <= self.term_end_time: new_contact_state = 'ing' @@ -916,7 +950,6 @@ class PropertyLeaseContract(models.Model): }) contract._update_contract_lines(contract) - def open_record(self): return { 'type': 'ir.actions.act_window', diff --git a/yuthon_property_approval/views/property_lease_contract.xml b/yuthon_property_approval/views/property_lease_contract.xml index f2ca476d2..6096f1307 100644 --- a/yuthon_property_approval/views/property_lease_contract.xml +++ b/yuthon_property_approval/views/property_lease_contract.xml @@ -66,6 +66,7 @@ +