diff --git a/yuthon_property_approval/models/inherit_yuthon_property.py b/yuthon_property_approval/models/inherit_yuthon_property.py index 6275fbef3..155761170 100644 --- a/yuthon_property_approval/models/inherit_yuthon_property.py +++ b/yuthon_property_approval/models/inherit_yuthon_property.py @@ -325,6 +325,26 @@ class PropertyBankStatements(models.Model): } } + def unbind(self): + statements_ids = self.env["property.bank.statements"].browse( + self._context.get('active_ids', self._context.get('active_id')) + ) + for statement in statements_ids: + if statement.name: + bank_account = self.env['property.bank.line'].search([ + ('bank', '=', statement.name) + ]) + if bank_account.tenant_id: + # 获取需要删除的合同明细行 + lines_to_delete = self.env['property.tenant.line'].search([ + ('tenant_id', '=', bank_account.tenant_id.id), + ('lease_contract_id', 'in', statement.contract_ids.ids) + ]) + # 删除合同明细行 + if lines_to_delete: + lines_to_delete.unlink() + statement.contract_ids = [(5,)] + def contract_penalty(self): statements_ids = self.env['property.bank.statements'].search([('is_put', '=', True)]) for record in statements_ids: