brotherton-erpnext/erpnext/patches/v6_2/remove_newsletter_duplicates.py
2015-09-17 17:47:26 +05:30

13 lines
443 B
Python

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