From d6a360b51bfb862fcc790ddb6c8cd706321339d4 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 30 Mar 2015 21:10:49 +0530 Subject: [PATCH] [fix] check job application unique email id --- erpnext/crm/doctype/lead/lead.py | 4 ++-- erpnext/hr/doctype/job_applicant/job_applicant.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/erpnext/crm/doctype/lead/lead.py b/erpnext/crm/doctype/lead/lead.py index 49a4e3de4a..009cfc2000 100644 --- a/erpnext/crm/doctype/lead/lead.py +++ b/erpnext/crm/doctype/lead/lead.py @@ -64,7 +64,7 @@ class Lead(SellingController): self.email_id) if len(email_list) > 1: items = [e[0] for e in email_list if e[0]!=self.name] - frappe.throw(_("Email id must be unique, already exists for {0}").format(comma_and(items))) + frappe.throw(_("Email id must be unique, already exists for {0}").format(comma_and(items)), frappe.DuplicateEntryError) def on_trash(self): frappe.db.sql("""update `tabIssue` set lead='' where lead=%s""", @@ -124,7 +124,7 @@ def make_opportunity(source_name, target_doc=None): }}, target_doc) return target_doc - + @frappe.whitelist() def make_quotation(source_name, target_doc=None): target_doc = get_mapped_doc("Lead", source_name, diff --git a/erpnext/hr/doctype/job_applicant/job_applicant.py b/erpnext/hr/doctype/job_applicant/job_applicant.py index eca767add0..d1901a85f1 100644 --- a/erpnext/hr/doctype/job_applicant/job_applicant.py +++ b/erpnext/hr/doctype/job_applicant/job_applicant.py @@ -7,6 +7,7 @@ from __future__ import unicode_literals from frappe.model.document import Document import frappe from frappe import _ +from frappe.utils import comma_and class JobApplicant(Document): def autoname(self): @@ -15,5 +16,16 @@ class JobApplicant(Document): frappe.throw(_("Name or Email is mandatory"), frappe.NameError) self.name = " - ".join(keys) + def validate(self): + self.check_email_id_is_unique() + + def check_email_id_is_unique(self): + if self.email_id: + names = frappe.db.sql_list("""select name from `tabJob Application` + where email_id=%s and name!=%s""", (self.email_id, self.name)) + + if names: + frappe.throw(_("Email id must be unique, already exists for {0}").format(comma_and(names)), frappe.DuplicateEntryError) + def set_sender(self, sender): self.email_id = sender