Moved lead assignment to the controller
diff --git a/erpnext/crm/doctype/appointment/appointment.py b/erpnext/crm/doctype/appointment/appointment.py
index 8a6d063..1ffd58f 100644
--- a/erpnext/crm/doctype/appointment/appointment.py
+++ b/erpnext/crm/doctype/appointment/appointment.py
@@ -20,6 +20,7 @@
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 @@
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 e238bd5..3370f24 100644
--- a/erpnext/www/book-appointment/index.py
+++ b/erpnext/www/book-appointment/index.py
@@ -97,15 +97,10 @@
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):