From 38bef0e4c9fc671adee343484ec3ac9632bbe296 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 16 Jul 2013 12:59:23 +0530 Subject: [PATCH] [patch] merge duplicate leads based on email id --- patches/july_2013/p04_merge_duplicate_leads.py | 13 +++++++++++++ patches/patch_list.py | 1 + 2 files changed, 14 insertions(+) create mode 100644 patches/july_2013/p04_merge_duplicate_leads.py diff --git a/patches/july_2013/p04_merge_duplicate_leads.py b/patches/july_2013/p04_merge_duplicate_leads.py new file mode 100644 index 0000000000..d3a5d20203 --- /dev/null +++ b/patches/july_2013/p04_merge_duplicate_leads.py @@ -0,0 +1,13 @@ +import webnotes +from webnotes.utils import extract_email_id + +def execute(): + email_lead = {} + for name, email in webnotes.conn.sql("""select name, email_id from `tabLead` + where ifnull(email_id, '')!='' order by creation asc"""): + email = extract_email_id(email) + if email: + if email not in email_lead: + email_lead[email] = name + else: + webnotes.rename("Lead", name, email_lead[email], merge=True) \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index af74a89574..f764d49cf3 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -251,4 +251,5 @@ patch_list = [ "patches.july_2013.p02_copy_shipping_address", "patches.july_2013.p03_cost_center_company", "execute:webnotes.bean('Style Settings').save() #2013-07-16", + "patches:july_2013.p04_merge_duplicate_leads" ] \ No newline at end of file