fix:readability

This commit is contained in:
Pranav Nachanekar 2019-10-04 11:32:39 +05:30
parent 9e36a9ee04
commit 25148d0de5
4 changed files with 192 additions and 163 deletions

View File

@ -19,13 +19,15 @@ 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)
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})
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')
@ -42,11 +44,13 @@ class Appointment(Document):
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])
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')
frappe.msgprint(
'Please check your email to confirm the appointment')
def get_verify_url(self):
verify_route = '/book-appointment/verify'
@ -72,6 +76,7 @@ class Appointment(Document):
if cal_event:
cal_event.delete()
# Delete task?
def set_verified(self, email):
if not email == self.customer_email:
frappe.throw('Email verification failed.')
@ -103,7 +108,8 @@ class Appointment(Document):
def auto_assign(self):
if self._assign:
return
available_agents = _get_agents_sorted_by_asc_workload(self.scheduled_time.date())
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]
@ -135,6 +141,7 @@ class Appointment(Document):
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()
@ -151,6 +158,7 @@ def _get_agents_sorted_by_asc_workload(date):
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
@ -158,15 +166,20 @@ def _get_agent_list_as_strings():
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})
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})
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
# frappe.db.exists returns a tuple of a tuple
return frappe.get_doc('Employee', employee_docname[0][0])
return None

View File

@ -7,6 +7,7 @@ import frappe
import unittest
import datetime
def create_test_lead():
test_lead = frappe.db.exists({'doctype': 'Lead', 'lead_name': 'Test Lead'})
if test_lead:
@ -19,8 +20,10 @@ def create_test_lead():
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])
test_appointment = frappe.get_doc({
@ -36,15 +39,19 @@ def create_test_appointments():
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)

View File

@ -211,7 +211,6 @@ async function submit() {
}
function get_form_data() {
contact = {};
contact.name = document.getElementById('customer_name').value;
contact.number = document.getElementById('customer_number').value;

View File

@ -9,21 +9,26 @@ WEEKDAYS = ["Monday", "Tuesday", "Wednesday",
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 @@ def filter_timeslots(date, timeslots):
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 @@ def _get_records(start_time, end_time, settings):
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)