添加功能

This commit is contained in:
李鹏宇
2026-08-17 11:59:10 +08:00
parent 7f33308292
commit 4b864f6f5e
2 changed files with 29 additions and 0 deletions
@@ -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'
@@ -180,6 +180,7 @@
<xpath expr="//tree" position="inside">
<header>
<button name="batch_push_deposit" type="object" string="推送" class="oe_highlight"/>
<button name="delete_duplicate_deposit" type="object" string="删除重复押金" confirm="确定要删除重复的押金记录吗?"/>
<button name="unlink" string="删除" type="object" icon="fa-trash" groups="base.group_system" confirm="确定要删除选中的记录吗?"/>
</header>
</xpath>