From 24f45af27e30a8355a5f0f2eeeffa4dd5ac5eb28 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 1 Aug 2016 16:06:54 +0530 Subject: [PATCH] [fix] minor dont make lead for invalid email --- erpnext/crm/doctype/opportunity/opportunity.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 79788822a6..0f4d1f4c26 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import frappe, json -from frappe.utils import cstr, cint, get_fullname +from frappe.utils import cstr, cint, get_fullname, validate_email_add from frappe import msgprint, _ from frappe.model.mapper import get_mapped_doc from erpnext.setup.utils import get_exchange_rate @@ -43,7 +43,7 @@ class Opportunity(TransactionBase): def make_new_lead_if_required(self): """Set lead against new opportunity""" - if not (self.lead or self.customer) and self.contact_email: + if not (self.lead or self.customer) and self.contact_email and validate_email_add(self.contact_email): lead_name = frappe.db.get_value("Lead", {"email_id": self.contact_email}) if not lead_name: sender_name = get_fullname(self.contact_email) @@ -63,6 +63,7 @@ class Opportunity(TransactionBase): "email_id": self.contact_email, "lead_name": sender_name }) + lead.insert(ignore_permissions=True) lead_name = lead.name