brotherton-erpnext/erpnext/patches/v6_2/remove_newsletter_duplicates.py
2016-06-28 17:28:40 +05:30

13 lines
407 B
Python

import frappe
def execute():
duplicates = frappe.db.sql("""select email_group, email, count(name)
from `tabEmail Group Member`
group by email_group, email
having count(name) > 1""")
# delete all duplicates except 1
for email_group, email, count in duplicates:
frappe.db.sql("""delete from `tabEmail Group Member`
where email_group=%s and email=%s limit %s""", (email_group, email, count-1))