diff --git a/erpnext/crm/doctype/appointment/appointment.py b/erpnext/crm/doctype/appointment/appointment.py
index 4dcb201..2da4acc 100644
--- a/erpnext/crm/doctype/appointment/appointment.py
+++ b/erpnext/crm/doctype/appointment/appointment.py
@@ -13,160 +13,173 @@
 from frappe.model.document import Document
 from frappe.desk.form.assign_to import add as add_assignemnt
 from frappe.utils import get_url
-from frappe.utils.verified_command import verify_request,get_signed_params
+from frappe.utils.verified_command import verify_request, get_signed_params
 
 
 class Appointment(Document):
 
-	def find_lead_by_email(self):
-		lead_list = frappe.get_list('Lead', filters = {'email_id':self.customer_email}, ignore_permissions = True)
-		if lead_list:
-			return lead_list[0].name
-		return None
-	
-	def before_insert(self):
-		number_of_appointments_in_same_slot = frappe.db.count('Appointment', filters = {'scheduled_time':self.scheduled_time})
-		settings = frappe.get_doc('Appointment Booking Settings')
-		if(number_of_appointments_in_same_slot >= settings.number_of_agents):
-			frappe.throw('Time slot is not available')
-		# Link lead
-		self.lead = self.find_lead_by_email()
+    def find_lead_by_email(self):
+        lead_list = frappe.get_list(
+            'Lead', filters={'email_id': self.customer_email}, ignore_permissions=True)
+        if lead_list:
+            return lead_list[0].name
+        return None
 
-	def after_insert(self):
-		if(self.lead):
-			# Create Calendar event
-			self.create_calendar_event()
-			self.auto_assign()
-		else:
-			# Set status to unverified
-			self.status = 'Unverified'
-			# Send email to confirm
-			verify_url = self.get_verify_url()
-			message = ''.join(['Please click the following link to confirm your appointment:',verify_url])
-			frappe.sendmail(recipients=[self.customer_email], 
-							message=message,
-							subject=_('Appointment Confirmation'))
-			frappe.msgprint('Please check your email to confirm the appointment')
+    def before_insert(self):
+        number_of_appointments_in_same_slot = frappe.db.count(
+            'Appointment', filters={'scheduled_time': self.scheduled_time})
+        settings = frappe.get_doc('Appointment Booking Settings')
+        if(number_of_appointments_in_same_slot >= settings.number_of_agents):
+            frappe.throw('Time slot is not available')
+        # Link lead
+        self.lead = self.find_lead_by_email()
 
-	def get_verify_url(self):
-		verify_route = '/book-appointment/verify'
+    def after_insert(self):
+        if(self.lead):
+            # Create Calendar event
+            self.create_calendar_event()
+            self.auto_assign()
+        else:
+            # Set status to unverified
+            self.status = 'Unverified'
+            # Send email to confirm
+            verify_url = self.get_verify_url()
+            message = ''.join(
+                ['Please click the following link to confirm your appointment:', verify_url])
+            frappe.sendmail(recipients=[self.customer_email],
+                            message=message,
+                            subject=_('Appointment Confirmation'))
+            frappe.msgprint(
+                'Please check your email to confirm the appointment')
 
-		params = {
-			'email':self.customer_email,
-			'appointment':self.name
-		}
+    def get_verify_url(self):
+        verify_route = '/book-appointment/verify'
 
-		return get_url(verify_route + '?' + get_signed_params(params))
+        params = {
+            'email': self.customer_email,
+            'appointment': self.name
+        }
 
-	def on_change(self):
-		# Sync Calednar
-		if not self.calendar_event:
-			return
-		cal_event = frappe.get_doc('Event',self.calendar_event)
-		cal_event.starts_on = self.scheduled_time
-		cal_event.save(ignore_permissions=True)
+        return get_url(verify_route + '?' + get_signed_params(params))
 
-	def on_trash(self):
-		# Delete calendar event
-		cal_event = frappe.get_doc('Event',self.calendar_event)
-		if cal_event:
-			cal_event.delete()
-		# Delete task?
-	def set_verified(self,email):
-		if not email == self.customer_email:
-			frappe.throw('Email verification failed.')
-		# Create new lead
-		self.create_lead()
-		# Remove unverified status
-		self.status = 'Open'
-		# Create calender event
-		self.create_calendar_event()
-		self.auto_assign()
-		self.save(ignore_permissions=True)
-		frappe.db.commit()
+    def on_change(self):
+        # Sync Calednar
+        if not self.calendar_event:
+            return
+        cal_event = frappe.get_doc('Event', self.calendar_event)
+        cal_event.starts_on = self.scheduled_time
+        cal_event.save(ignore_permissions=True)
 
-	def create_lead(self):
-		# Return if already linked
-		if self.lead:
-			return
-		lead = frappe.get_doc({
-			'doctype':'Lead',
-			'lead_name':self.customer_name,
-			'email_id':self.customer_email,
-			'notes':self.customer_details,
-			'phone':self.customer_phone_number,
-		})
-		lead.insert(ignore_permissions=True)
-		# Link lead
-		self.lead = lead.name
+    def on_trash(self):
+        # Delete calendar event
+        cal_event = frappe.get_doc('Event', self.calendar_event)
+        if cal_event:
+            cal_event.delete()
+        # Delete task?
 
-	def auto_assign(self):
-		if self._assign:
-			return
-		available_agents = _get_agents_sorted_by_asc_workload(self.scheduled_time.date())
-		for agent in available_agents:
-			if(_check_agent_availability(agent, self.scheduled_time)):
-				agent = agent[0]
-				add_assignemnt({
-					'doctype':self.doctype,
-					'name':self.name,
-					'assign_to':agent
-				})
-			break
+    def set_verified(self, email):
+        if not email == self.customer_email:
+            frappe.throw('Email verification failed.')
+        # Create new lead
+        self.create_lead()
+        # Remove unverified status
+        self.status = 'Open'
+        # Create calender event
+        self.create_calendar_event()
+        self.auto_assign()
+        self.save(ignore_permissions=True)
+        frappe.db.commit()
 
-	def create_calendar_event(self):
-		if self.calendar_event:
-			return
-		appointment_event = frappe.get_doc({
-			'doctype': 'Event',
-			'subject': ' '.join(['Appointment with', self.customer_name]),
-			'starts_on': self.scheduled_time,
-			'status': 'Open',
-			'type': 'Public',
-			'send_reminder': frappe.db.get_single_value('Appointment Booking Settings','email_reminders'),
-			'event_participants': [dict(reference_doctype = 'Lead', reference_docname = self.lead)]
-		})
-		employee = _get_employee_from_user(self._assign)
-		if employee:
-			appointment_event.append('event_participants', dict(
-				reference_doctype = 'Employee',
-				reference_docname = employee.name))
-		appointment_event.insert(ignore_permissions=True)
-		self.calendar_event = appointment_event.name
-		self.save(ignore_permissions=True)
+    def create_lead(self):
+        # Return if already linked
+        if self.lead:
+            return
+        lead = frappe.get_doc({
+            'doctype': 'Lead',
+            'lead_name': self.customer_name,
+            'email_id': self.customer_email,
+            'notes': self.customer_details,
+            'phone': self.customer_phone_number,
+        })
+        lead.insert(ignore_permissions=True)
+        # Link lead
+        self.lead = lead.name
+
+    def auto_assign(self):
+        if self._assign:
+            return
+        available_agents = _get_agents_sorted_by_asc_workload(
+            self.scheduled_time.date())
+        for agent in available_agents:
+            if(_check_agent_availability(agent, self.scheduled_time)):
+                agent = agent[0]
+                add_assignemnt({
+                    'doctype': self.doctype,
+                    'name': self.name,
+                    'assign_to': agent
+                })
+            break
+
+    def create_calendar_event(self):
+        if self.calendar_event:
+            return
+        appointment_event = frappe.get_doc({
+            'doctype': 'Event',
+            'subject': ' '.join(['Appointment with', self.customer_name]),
+            'starts_on': self.scheduled_time,
+            'status': 'Open',
+            'type': 'Public',
+            'send_reminder': frappe.db.get_single_value('Appointment Booking Settings', 'email_reminders'),
+            'event_participants': [dict(reference_doctype='Lead', reference_docname=self.lead)]
+        })
+        employee = _get_employee_from_user(self._assign)
+        if employee:
+            appointment_event.append('event_participants', dict(
+                reference_doctype='Employee',
+                reference_docname=employee.name))
+        appointment_event.insert(ignore_permissions=True)
+        self.calendar_event = appointment_event.name
+        self.save(ignore_permissions=True)
+
 
 def _get_agents_sorted_by_asc_workload(date):
-	appointments = frappe.db.get_list('Appointment', fields='*')
-	agent_list = _get_agent_list_as_strings()	
-	if not appointments:
-		return agent_list
-	appointment_counter = Counter(agent_list)
-	for appointment in appointments:
-		assigned_to = frappe.parse_json(appointment._assign)
-		if not assigned_to:
-			continue
-		if (assigned_to[0] in agent_list) and appointment.scheduled_time.date() == date:
-			appointment_counter[assigned_to[0]] += 1
-	sorted_agent_list = appointment_counter.most_common()
-	sorted_agent_list.reverse()
-	return sorted_agent_list
+    appointments = frappe.db.get_list('Appointment', fields='*')
+    agent_list = _get_agent_list_as_strings()
+    if not appointments:
+        return agent_list
+    appointment_counter = Counter(agent_list)
+    for appointment in appointments:
+        assigned_to = frappe.parse_json(appointment._assign)
+        if not assigned_to:
+            continue
+        if (assigned_to[0] in agent_list) and appointment.scheduled_time.date() == date:
+            appointment_counter[assigned_to[0]] += 1
+    sorted_agent_list = appointment_counter.most_common()
+    sorted_agent_list.reverse()
+    return sorted_agent_list
+
 
 def _get_agent_list_as_strings():
-	agent_list_as_strings = []
-	agent_list = frappe.get_doc('Appointment Booking Settings').agent_list
-	for agent in agent_list:
-		agent_list_as_strings.append(agent.user)
-	return agent_list_as_strings
+    agent_list_as_strings = []
+    agent_list = frappe.get_doc('Appointment Booking Settings').agent_list
+    for agent in agent_list:
+        agent_list_as_strings.append(agent.user)
+    return agent_list_as_strings
 
-def _check_agent_availability(agent_email,scheduled_time):
-	appointemnts_at_scheduled_time = frappe.get_list('Appointment', filters = {'scheduled_time':scheduled_time})
-	for appointment in appointemnts_at_scheduled_time:
-		if appointment._assign == agent_email:
-			return False
-	return True
+
+def _check_agent_availability(agent_email, scheduled_time):
+    appointemnts_at_scheduled_time = frappe.get_list(
+        'Appointment', filters={'scheduled_time': scheduled_time})
+    for appointment in appointemnts_at_scheduled_time:
+        if appointment._assign == agent_email:
+            return False
+    return True
+
 
 def _get_employee_from_user(user):
-	employee_docname = frappe.db.exists({'doctype':'Employee', 'user_id':user})
-	if employee_docname:
-		return frappe.get_doc('Employee', employee_docname[0][0]) # frappe.db.exists returns a tuple of a tuple
-	return None
\ No newline at end of file
+    employee_docname = frappe.db.exists(
+        {'doctype': 'Employee', 'user_id': user})
+    if employee_docname:
+        # frappe.db.exists returns a tuple of a tuple
+        return frappe.get_doc('Employee', employee_docname[0][0])
+    return None
diff --git a/erpnext/crm/doctype/appointment/test_appointment.py b/erpnext/crm/doctype/appointment/test_appointment.py
index b22e6e0..72c2ae5 100644
--- a/erpnext/crm/doctype/appointment/test_appointment.py
+++ b/erpnext/crm/doctype/appointment/test_appointment.py
@@ -7,45 +7,52 @@
 import unittest
 import datetime
 
+
 def create_test_lead():
-    test_lead = frappe.db.exists({'doctype':'Lead','lead_name':'Test Lead'})
+    test_lead = frappe.db.exists({'doctype': 'Lead', 'lead_name': 'Test Lead'})
     if test_lead:
-        return frappe.get_doc('Lead',test_lead[0][0])
+        return frappe.get_doc('Lead', test_lead[0][0])
     test_lead = frappe.get_doc({
-        'doctype':'Lead',
-        'lead_name':'Test Lead',
-        'email_id':'test@example.com'
+        'doctype': 'Lead',
+        'lead_name': 'Test Lead',
+        'email_id': 'test@example.com'
     })
     test_lead.insert(ignore_permissions=True)
     return test_lead
 
+
 def create_test_appointments():
-    test_appointment = frappe.db.exists({ 'doctype':'Appointment', 'email':'test@example.com' })
+    test_appointment = frappe.db.exists(
+        {'doctype': 'Appointment', 'email': 'test@example.com'})
     if test_appointment:
-        return frappe.get_doc('Appointment',test_appointment[0][0])
+        return frappe.get_doc('Appointment', test_appointment[0][0])
     test_appointment = frappe.get_doc({
-        'doctype':'Appointment',
-        'email':'test@example.com',
-        'status':'Open',
-        'customer_name':'Test Lead',
-        'customer_phone_number':'666',
-        'customer_skype':'test',
-        'customer_email':'test@example.com',
-        'scheduled_time':datetime.datetime.now()
+        'doctype': 'Appointment',
+        'email': 'test@example.com',
+        'status': 'Open',
+        'customer_name': 'Test Lead',
+        'customer_phone_number': '666',
+        'customer_skype': 'test',
+        'customer_email': 'test@example.com',
+        'scheduled_time': datetime.datetime.now()
     })
     test_appointment.insert()
     return test_appointment
 
+
 class TestAppointment(unittest.TestCase):
     test_appointment = test_lead = None
+
     def setUp(self):
         self.test_lead = create_test_lead()
         self.test_appointment = create_test_appointments()
 
     def test_calendar_event_created(self):
-        cal_event = frappe.get_doc('Event',self.test_appointment.calendar_event)
-        self.assertEqual(cal_event.starts_on ,self.test_appointment.scheduled_time)
+        cal_event = frappe.get_doc(
+            'Event', self.test_appointment.calendar_event)
+        self.assertEqual(cal_event.starts_on,
+                         self.test_appointment.scheduled_time)
 
     def test_lead_linked(self):
-        lead = frappe.get_doc('Lead',self.test_lead.name)
-        self.assertIsNotNone(lead)
\ No newline at end of file
+        lead = frappe.get_doc('Lead', self.test_lead.name)
+        self.assertIsNotNone(lead)
diff --git a/erpnext/www/book-appointment/index.js b/erpnext/www/book-appointment/index.js
index cfacc79..f0cf1d7 100644
--- a/erpnext/www/book-appointment/index.js
+++ b/erpnext/www/book-appointment/index.js
@@ -34,7 +34,7 @@
     window.timezones.forEach(timezone => {
         let opt = document.createElement('option');
         opt.value = timezone;
-        if(timezone == moment.tz.guess()){
+        if (timezone == moment.tz.guess()) {
             opt.selected = true;
         }
         opt.innerHTML = timezone;
@@ -140,7 +140,7 @@
         return;
     }
     let selected_element = document.getElementsByClassName('selected');
-    if (!(selected_element.length > 0)){
+    if (!(selected_element.length > 0)) {
         this.classList.add('selected');
         show_next_button();
         return;
@@ -191,7 +191,7 @@
 
 async function submit() {
     let form = document.querySelector('#customer-form');
-    if(!form.checkValidity()){
+    if (!form.checkValidity()) {
         form.reportValidity();
         return;
     }
@@ -211,7 +211,6 @@
 }
 
 function get_form_data() {
-    
     contact = {};
     contact.name = document.getElementById('customer_name').value;
     contact.number = document.getElementById('customer_number').value;
diff --git a/erpnext/www/book-appointment/index.py b/erpnext/www/book-appointment/index.py
index 1a9afa5..e279a47 100644
--- a/erpnext/www/book-appointment/index.py
+++ b/erpnext/www/book-appointment/index.py
@@ -9,21 +9,26 @@
 
 no_cache = 1
 
+
 def get_context(context):
-    is_enabled = frappe.db.get_single_value('Appointment Booking Settings','enable_scheduling')
+    is_enabled = frappe.db.get_single_value(
+        'Appointment Booking Settings', 'enable_scheduling')
     if is_enabled:
         return context
     else:
         raise frappe.DoesNotExistError
 
+
 @frappe.whitelist(allow_guest=True)
 def get_appointment_settings():
     settings = frappe.get_doc('Appointment Booking Settings')
     return settings
 
+
 @frappe.whitelist(allow_guest=True)
 def is_enabled():
-    enable_scheduling = frappe.db.get_single_value('Appointment Booking Settings','enable_scheduling')
+    enable_scheduling = frappe.db.get_single_value(
+        'Appointment Booking Settings', 'enable_scheduling')
     return enable_scheduling
 
 
@@ -131,15 +136,18 @@
             filtered_timeslots.append(timeslot)
     return filtered_timeslots
 
+
 def check_availabilty(timeslot, settings):
     return frappe.db.count('Appointment', {'scheduled_time': timeslot}) < settings.number_of_agents
 
+
 def _is_holiday(date, holiday_list):
     for holiday in holiday_list.holidays:
         if holiday.holiday_date == date:
             return True
     return False
 
+
 def _get_records(start_time, end_time, settings):
     records = []
     for record in settings.availability_of_slots:
@@ -147,10 +155,12 @@
             records.append(record)
     return records
 
+
 def _deltatime_to_datetime(date, deltatime):
     time = (datetime.datetime.min + deltatime).time()
     return datetime.datetime.combine(date.date(), time)
 
+
 def _datetime_to_deltatime(date_time):
     midnight = datetime.datetime.combine(date_time.date(), datetime.time.min)
-    return (date_time-midnight)
\ No newline at end of file
+    return (date_time-midnight)
