mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-21 05:59:18 +00:00
Merge pull request #28436 from anupamvs/crm-lead-validate-cleanup
fix: lead validate function cleanup
This commit is contained in:
@@ -8,15 +8,7 @@ from frappe import _
|
|||||||
from frappe.contacts.address_and_contact import load_address_and_contact
|
from frappe.contacts.address_and_contact import load_address_and_contact
|
||||||
from frappe.email.inbox import link_communication_to_document
|
from frappe.email.inbox import link_communication_to_document
|
||||||
from frappe.model.mapper import get_mapped_doc
|
from frappe.model.mapper import get_mapped_doc
|
||||||
from frappe.utils import (
|
from frappe.utils import comma_and, cstr, getdate, has_gravatar, nowdate, validate_email_address
|
||||||
cint,
|
|
||||||
comma_and,
|
|
||||||
cstr,
|
|
||||||
getdate,
|
|
||||||
has_gravatar,
|
|
||||||
nowdate,
|
|
||||||
validate_email_address,
|
|
||||||
)
|
|
||||||
|
|
||||||
from erpnext.accounts.party import set_taxes
|
from erpnext.accounts.party import set_taxes
|
||||||
from erpnext.controllers.selling_controller import SellingController
|
from erpnext.controllers.selling_controller import SellingController
|
||||||
@@ -42,15 +34,13 @@ class Lead(SellingController):
|
|||||||
def validate(self):
|
def validate(self):
|
||||||
self.set_lead_name()
|
self.set_lead_name()
|
||||||
self.set_title()
|
self.set_title()
|
||||||
self._prev = frappe._dict({
|
|
||||||
"contact_date": frappe.db.get_value("Lead", self.name, "contact_date") if (not cint(self.is_new())) else None,
|
|
||||||
"ends_on": frappe.db.get_value("Lead", self.name, "ends_on") if (not cint(self.is_new())) else None,
|
|
||||||
"contact_by": frappe.db.get_value("Lead", self.name, "contact_by") if (not cint(self.is_new())) else None,
|
|
||||||
})
|
|
||||||
|
|
||||||
self.set_status()
|
self.set_status()
|
||||||
self.check_email_id_is_unique()
|
self.check_email_id_is_unique()
|
||||||
|
self.validate_email_id()
|
||||||
|
self.validate_contact_date()
|
||||||
|
self.set_prev()
|
||||||
|
|
||||||
|
def validate_email_id(self):
|
||||||
if self.email_id:
|
if self.email_id:
|
||||||
if not self.flags.ignore_email_validation:
|
if not self.flags.ignore_email_validation:
|
||||||
validate_email_address(self.email_id, throw=True)
|
validate_email_address(self.email_id, throw=True)
|
||||||
@@ -64,6 +54,7 @@ class Lead(SellingController):
|
|||||||
if self.is_new() or not self.image:
|
if self.is_new() or not self.image:
|
||||||
self.image = has_gravatar(self.email_id)
|
self.image = has_gravatar(self.email_id)
|
||||||
|
|
||||||
|
def validate_contact_date(self):
|
||||||
if self.contact_date and getdate(self.contact_date) < getdate(nowdate()):
|
if self.contact_date and getdate(self.contact_date) < getdate(nowdate()):
|
||||||
frappe.throw(_("Next Contact Date cannot be in the past"))
|
frappe.throw(_("Next Contact Date cannot be in the past"))
|
||||||
|
|
||||||
@@ -74,6 +65,16 @@ class Lead(SellingController):
|
|||||||
def on_update(self):
|
def on_update(self):
|
||||||
self.add_calendar_event()
|
self.add_calendar_event()
|
||||||
|
|
||||||
|
def set_prev(self):
|
||||||
|
if self.is_new():
|
||||||
|
self._prev = frappe._dict({
|
||||||
|
"contact_date": None,
|
||||||
|
"ends_on": None,
|
||||||
|
"contact_by": None
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
self._prev = frappe.db.get_value("Lead", self.name, ["contact_date", "ends_on", "contact_by"], as_dict=1)
|
||||||
|
|
||||||
def add_calendar_event(self, opts=None, force=False):
|
def add_calendar_event(self, opts=None, force=False):
|
||||||
super(Lead, self).add_calendar_event({
|
super(Lead, self).add_calendar_event({
|
||||||
"owner": self.lead_owner,
|
"owner": self.lead_owner,
|
||||||
|
|||||||
Reference in New Issue
Block a user