seitime-frappe/frappe/patches/v11_0/delete_duplicate_user_permissions.py
Ankush Menat 81b37cb7d2
refactor: clean up code to py310 supported features (#17367)
refactor: clean up code to py39+ supported syntax

- f-strings instead of format
- latest typing support instead of pre 3.9 TitleCase
- remove UTF-8 declarations.
- many more changes

Powered by https://github.com/asottile/pyupgrade/ + manual cleanups
2022-07-01 11:51:05 +05:30

20 lines
468 B
Python

import frappe
def execute():
duplicateRecords = frappe.db.sql(
"""select count(name) as `count`, allow, user, for_value
from `tabUser Permission`
group by allow, user, for_value
having count(*) > 1 """,
as_dict=1,
)
for record in duplicateRecords:
frappe.db.sql(
"""delete from `tabUser Permission`
where allow=%s and user=%s and for_value=%s limit {}""".format(
record.count - 1
),
(record.allow, record.user, record.for_value),
)