fix: generate lead_name and some other validations
This commit is contained in:
parent
6f631d9e07
commit
e9762935f7
@ -1,9 +1,46 @@
|
|||||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
# import frappe
|
import frappe
|
||||||
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
from frappe.utils import has_gravatar, validate_email_address
|
||||||
|
|
||||||
|
|
||||||
class CRMLead(Document):
|
class CRMLead(Document):
|
||||||
pass
|
def validate(self):
|
||||||
|
self.set_full_name()
|
||||||
|
self.set_lead_name()
|
||||||
|
self.set_title()
|
||||||
|
self.validate_email()
|
||||||
|
|
||||||
|
def set_full_name(self):
|
||||||
|
if self.first_name:
|
||||||
|
self.lead_name = " ".join(
|
||||||
|
filter(None, [self.salutation, self.first_name, self.middle_name, self.last_name])
|
||||||
|
)
|
||||||
|
|
||||||
|
def set_lead_name(self):
|
||||||
|
if not self.lead_name:
|
||||||
|
# Check for leads being created through data import
|
||||||
|
if not self.organization_name and not self.email and not self.flags.ignore_mandatory:
|
||||||
|
frappe.throw(_("A Lead requires either a person's name or an organization's name"))
|
||||||
|
elif self.organization_name:
|
||||||
|
self.lead_name = self.organization_name
|
||||||
|
else:
|
||||||
|
self.lead_name = self.email.split("@")[0]
|
||||||
|
|
||||||
|
def set_title(self):
|
||||||
|
self.title = self.organization_name or self.lead_name
|
||||||
|
|
||||||
|
def validate_email(self):
|
||||||
|
if self.email:
|
||||||
|
if not self.flags.ignore_email_validation:
|
||||||
|
validate_email_address(self.email, throw=True)
|
||||||
|
|
||||||
|
if self.email == self.lead_owner:
|
||||||
|
frappe.throw(_("Lead Owner cannot be same as the Lead Email Address"))
|
||||||
|
|
||||||
|
if self.is_new() or not self.image:
|
||||||
|
self.image = has_gravatar(self.email)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user