From 7d476a3e353dcb1ca711208ee111dbe5b80b00b2 Mon Sep 17 00:00:00 2001 From: Pranav Nachanekar Date: Wed, 18 Sep 2019 15:33:31 +0530 Subject: [PATCH] Moved lead assignment to the controller --- erpnext/crm/doctype/appointment/appointment.py | 7 +++++++ erpnext/www/book-appointment/index.py | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/erpnext/crm/doctype/appointment/appointment.py b/erpnext/crm/doctype/appointment/appointment.py index 8a6d0635bc..1ffd58fa04 100644 --- a/erpnext/crm/doctype/appointment/appointment.py +++ b/erpnext/crm/doctype/appointment/appointment.py @@ -20,6 +20,7 @@ class Appointment(Document): frappe.throw('Time slot is not available') def before_insert(self): + self.lead = _find_lead_by_email(self.lead).name appointment_event = frappe.get_doc({ 'doctype': 'Event', 'subject': ' '.join(['Appointment with', self.customer_name]), @@ -67,6 +68,12 @@ def _get_agents_sorted_by_asc_workload(): return sorted_agent_list +def _find_lead_by_email(email): + lead_list = frappe.get_list('Lead',filters={'email_id':email},ignore_permissions=True) + if lead_list: + return lead_list[0] + frappe.throw('Email ID not associated with any Lead. Please make sure to use the email address you got this mail on') + def _get_agent_list_as_strings(): agent_list_as_strings = [] diff --git a/erpnext/www/book-appointment/index.py b/erpnext/www/book-appointment/index.py index e238bd5205..3370f2429e 100644 --- a/erpnext/www/book-appointment/index.py +++ b/erpnext/www/book-appointment/index.py @@ -97,15 +97,10 @@ def create_appointment(date, time, contact): appointment.customer_phone_number = contact['number'] appointment.customer_skype = contact['skype'] appointment.customer_details = contact['notes'] + appointment.lead = contact['email'] appointment.status = 'Open' - appointment.lead = find_lead_by_email(contact['email']).name appointment.insert() -def find_lead_by_email(email): - lead_list = frappe.get_list('Lead',filters={'email_id':email},ignore_permissions=True) - if lead_list: - return lead_list[0] - frappe.throw('Email ID not associated with any Lead. Please make sure to use the email address you got this mail on') # Helper Functions def filter_timeslots(date, timeslots):