[fix] check job application unique email id
diff --git a/erpnext/crm/doctype/lead/lead.py b/erpnext/crm/doctype/lead/lead.py
index 49a4e3d..009cfc2 100644
--- a/erpnext/crm/doctype/lead/lead.py
+++ b/erpnext/crm/doctype/lead/lead.py
@@ -64,7 +64,7 @@
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 @@
}}, 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 eca767a..d1901a8 100644
--- a/erpnext/hr/doctype/job_applicant/job_applicant.py
+++ b/erpnext/hr/doctype/job_applicant/job_applicant.py
@@ -7,6 +7,7 @@
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 @@
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