Moved lead assignment to the controller

This commit is contained in:
Pranav Nachanekar 2019-09-18 15:33:31 +05:30
parent 81449ece54
commit 7d476a3e35
2 changed files with 8 additions and 6 deletions

View File

@ -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 = []

View File

@ -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):