[patch] merge duplicate leads based on email id
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 0000000..d3a5d20
--- /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 af74a89..f764d49 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -251,4 +251,5 @@
 	"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