[fix] Validate duplicate email ids in Lead

This commit is contained in:
Nabin Hait 2015-10-01 11:51:48 +05:30
parent e2c3d40b57
commit f924e08b93

View File

@ -58,12 +58,12 @@ class Lead(SellingController):
def check_email_id_is_unique(self): def check_email_id_is_unique(self):
if self.email_id: if self.email_id:
# validate email is unique # validate email is unique
email_list = frappe.db.sql("""select name from tabLead where email_id=%s""", duplicate_leads = frappe.db.sql_list("""select name from tabLead
self.email_id) where email_id=%s and name!=%s""", (self.email_id, self.name))
email_list = [e[0] for e in email_list if e[0]!=self.name]
if len(email_list) > 1: if duplicate_leads:
frappe.throw(_("Email id must be unique, already exists for {0}").format(comma_and(email_list)), frappe.throw(_("Email id must be unique, already exists for {0}")
frappe.DuplicateEntryError) .format(comma_and(duplicate_leads)), frappe.DuplicateEntryError)
def on_trash(self): def on_trash(self):
frappe.db.sql("""update `tabIssue` set lead='' where lead=%s""", frappe.db.sql("""update `tabIssue` set lead='' where lead=%s""",