Moved lead assignment to the controller
This commit is contained in:
parent
81449ece54
commit
7d476a3e35
@ -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 = []
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user