From 66a10c0e73174d9469517350758504af7a146b5c Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Mon, 20 Dec 2021 18:12:57 +0530 Subject: [PATCH] Merge pull request #28440 from anupamvs/crm-lead-validate-cleanup-develop fix: lead validate function cleanup --- erpnext/crm/doctype/lead/lead.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/erpnext/crm/doctype/lead/lead.py b/erpnext/crm/doctype/lead/lead.py index 9adbe8b6f1..c31b068a43 100644 --- a/erpnext/crm/doctype/lead/lead.py +++ b/erpnext/crm/doctype/lead/lead.py @@ -8,7 +8,6 @@ from frappe.contacts.address_and_contact import load_address_and_contact from frappe.email.inbox import link_communication_to_document from frappe.model.mapper import get_mapped_doc from frappe.utils import ( - cint, comma_and, cstr, get_link_to_form, @@ -39,11 +38,7 @@ class Lead(SellingController): self.check_email_id_is_unique() self.validate_email_id() self.validate_contact_date() - 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_prev() def set_full_name(self): if self.first_name: @@ -75,6 +70,16 @@ class Lead(SellingController): self.add_calendar_event() self.update_prospects() + 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 before_insert(self): self.contact_doc = self.create_contact()