brotherton-erpnext/erpnext/patches/v6_2/remove_newsletter_duplicates.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

14 lines
447 B
Python
Raw Normal View History

from __future__ import unicode_literals
import frappe
def execute():
2016-06-28 05:47:02 +00:00
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
2016-06-28 05:47:02 +00:00
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))