diff --git a/yuthon_property_approval/models/inherit_yuthon_property.py b/yuthon_property_approval/models/inherit_yuthon_property.py index 0a6ea34d0..d4e1a0a24 100644 --- a/yuthon_property_approval/models/inherit_yuthon_property.py +++ b/yuthon_property_approval/models/inherit_yuthon_property.py @@ -1551,6 +1551,34 @@ class PropertyDepositList(models.Model): }) rec.is_push = True + def delete_duplicate_deposit(self): + """删除重复押金:同一合同 + 同一保证金类型只保留最早一条,删除其余""" + deposits = self.env['property.deposit.list'].search([ + ('contract_id', '!=', False), + ('posit_type', '!=', False), + ]) + seen = {} + to_delete = self.env['property.deposit.list'] + for dep in deposits.sorted(key=lambda d: (d.contract_id.id, d.posit_type, d.id)): + key = (dep.contract_id.id, dep.posit_type) + if key in seen: + to_delete |= dep + else: + seen[key] = dep.id + count = len(to_delete) + if to_delete: + to_delete.unlink() + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { + 'title': '删除重复押金', + 'message': f'已删除 {count} 条重复押金记录' if count else '没有重复的押金记录', + 'type': 'success' if count else 'info', + 'sticky': False, + }, + } + # 管理费 class PropertyManagementList(models.Model): _inherit = 'property.management.list' diff --git a/yuthon_property_approval/views/inherit_yuthon_property_views.xml b/yuthon_property_approval/views/inherit_yuthon_property_views.xml index d8c7fd8f3..8568815e1 100644 --- a/yuthon_property_approval/views/inherit_yuthon_property_views.xml +++ b/yuthon_property_approval/views/inherit_yuthon_property_views.xml @@ -180,6 +180,7 @@