mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 12:19:12 +00:00
fix: lead validate function cleanup
This commit is contained in:
@@ -42,15 +42,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 +62,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 +73,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