diff --git a/yuthon_property/models/property_tenant_information.py b/yuthon_property/models/property_tenant_information.py index 9defc252b..6defe2b09 100644 --- a/yuthon_property/models/property_tenant_information.py +++ b/yuthon_property/models/property_tenant_information.py @@ -48,6 +48,38 @@ class PropertyTenantInformation(models.Model): if bank_id.name == False and bank_id.user == False and bank_id.bank == False: bank_id.unlink() + def batch_delete_invalid_invoicing_lines(self): + """批量删除没有生效日期的开票信息明细记录""" + # 查找所有生效日期为空的开票信息明细 + invalid_lines = self.env['invoicing.information.line'].search([ + ('start_date', '=', False) + ]) + + count = len(invalid_lines) + if count > 0: + invalid_lines.unlink() + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { + 'title': '删除成功', + 'message': f'已成功删除 {count} 条没有生效日期的开票信息明细记录', + 'type': 'success', + 'sticky': False, + } + } + else: + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { + 'title': '提示', + 'message': '没有找到需要删除的记录', + 'type': 'info', + 'sticky': False, + } + } + @api.depends('invoicing_ids', 'invoicing_ids.start_date', 'invoicing_ids.end_date', 'invoicing_ids.scope_business', 'invoicing_ids.invoicing_type', 'invoicing_ids.tax_number', 'invoicing_ids.invoicing_begins') diff --git a/yuthon_property/views/property_tenant_information_views.xml b/yuthon_property/views/property_tenant_information_views.xml index d001fc76e..08092fa75 100644 --- a/yuthon_property/views/property_tenant_information_views.xml +++ b/yuthon_property/views/property_tenant_information_views.xml @@ -94,4 +94,11 @@ code action = model.update_tenant_wizard() + + 批量删除无生效日期的开票信息 + + + code + action = env['property.tenant.information'].batch_delete_invalid_invoicing_lines() + \ No newline at end of file