fix:readability
This commit is contained in:
parent
9e36a9ee04
commit
25148d0de5
@ -19,13 +19,15 @@ from frappe.utils.verified_command import verify_request,get_signed_params
|
|||||||
class Appointment(Document):
|
class Appointment(Document):
|
||||||
|
|
||||||
def find_lead_by_email(self):
|
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:
|
if lead_list:
|
||||||
return lead_list[0].name
|
return lead_list[0].name
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def before_insert(self):
|
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')
|
settings = frappe.get_doc('Appointment Booking Settings')
|
||||||
if(number_of_appointments_in_same_slot >= settings.number_of_agents):
|
if(number_of_appointments_in_same_slot >= settings.number_of_agents):
|
||||||
frappe.throw('Time slot is not available')
|
frappe.throw('Time slot is not available')
|
||||||
@ -42,11 +44,13 @@ class Appointment(Document):
|
|||||||
self.status = 'Unverified'
|
self.status = 'Unverified'
|
||||||
# Send email to confirm
|
# Send email to confirm
|
||||||
verify_url = self.get_verify_url()
|
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],
|
frappe.sendmail(recipients=[self.customer_email],
|
||||||
message=message,
|
message=message,
|
||||||
subject=_('Appointment Confirmation'))
|
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):
|
def get_verify_url(self):
|
||||||
verify_route = '/book-appointment/verify'
|
verify_route = '/book-appointment/verify'
|
||||||
@ -72,6 +76,7 @@ class Appointment(Document):
|
|||||||
if cal_event:
|
if cal_event:
|
||||||
cal_event.delete()
|
cal_event.delete()
|
||||||
# Delete task?
|
# Delete task?
|
||||||
|
|
||||||
def set_verified(self, email):
|
def set_verified(self, email):
|
||||||
if not email == self.customer_email:
|
if not email == self.customer_email:
|
||||||
frappe.throw('Email verification failed.')
|
frappe.throw('Email verification failed.')
|
||||||
@ -103,7 +108,8 @@ class Appointment(Document):
|
|||||||
def auto_assign(self):
|
def auto_assign(self):
|
||||||
if self._assign:
|
if self._assign:
|
||||||
return
|
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:
|
for agent in available_agents:
|
||||||
if(_check_agent_availability(agent, self.scheduled_time)):
|
if(_check_agent_availability(agent, self.scheduled_time)):
|
||||||
agent = agent[0]
|
agent = agent[0]
|
||||||
@ -135,6 +141,7 @@ class Appointment(Document):
|
|||||||
self.calendar_event = appointment_event.name
|
self.calendar_event = appointment_event.name
|
||||||
self.save(ignore_permissions=True)
|
self.save(ignore_permissions=True)
|
||||||
|
|
||||||
|
|
||||||
def _get_agents_sorted_by_asc_workload(date):
|
def _get_agents_sorted_by_asc_workload(date):
|
||||||
appointments = frappe.db.get_list('Appointment', fields='*')
|
appointments = frappe.db.get_list('Appointment', fields='*')
|
||||||
agent_list = _get_agent_list_as_strings()
|
agent_list = _get_agent_list_as_strings()
|
||||||
@ -151,6 +158,7 @@ def _get_agents_sorted_by_asc_workload(date):
|
|||||||
sorted_agent_list.reverse()
|
sorted_agent_list.reverse()
|
||||||
return sorted_agent_list
|
return sorted_agent_list
|
||||||
|
|
||||||
|
|
||||||
def _get_agent_list_as_strings():
|
def _get_agent_list_as_strings():
|
||||||
agent_list_as_strings = []
|
agent_list_as_strings = []
|
||||||
agent_list = frappe.get_doc('Appointment Booking Settings').agent_list
|
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)
|
agent_list_as_strings.append(agent.user)
|
||||||
return agent_list_as_strings
|
return agent_list_as_strings
|
||||||
|
|
||||||
|
|
||||||
def _check_agent_availability(agent_email, scheduled_time):
|
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:
|
for appointment in appointemnts_at_scheduled_time:
|
||||||
if appointment._assign == agent_email:
|
if appointment._assign == agent_email:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _get_employee_from_user(user):
|
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:
|
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
|
return None
|
||||||
@ -7,6 +7,7 @@ import frappe
|
|||||||
import unittest
|
import unittest
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
def create_test_lead():
|
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:
|
if test_lead:
|
||||||
@ -19,8 +20,10 @@ def create_test_lead():
|
|||||||
test_lead.insert(ignore_permissions=True)
|
test_lead.insert(ignore_permissions=True)
|
||||||
return test_lead
|
return test_lead
|
||||||
|
|
||||||
|
|
||||||
def create_test_appointments():
|
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:
|
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({
|
test_appointment = frappe.get_doc({
|
||||||
@ -36,15 +39,19 @@ def create_test_appointments():
|
|||||||
test_appointment.insert()
|
test_appointment.insert()
|
||||||
return test_appointment
|
return test_appointment
|
||||||
|
|
||||||
|
|
||||||
class TestAppointment(unittest.TestCase):
|
class TestAppointment(unittest.TestCase):
|
||||||
test_appointment = test_lead = None
|
test_appointment = test_lead = None
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.test_lead = create_test_lead()
|
self.test_lead = create_test_lead()
|
||||||
self.test_appointment = create_test_appointments()
|
self.test_appointment = create_test_appointments()
|
||||||
|
|
||||||
def test_calendar_event_created(self):
|
def test_calendar_event_created(self):
|
||||||
cal_event = frappe.get_doc('Event',self.test_appointment.calendar_event)
|
cal_event = frappe.get_doc(
|
||||||
self.assertEqual(cal_event.starts_on ,self.test_appointment.scheduled_time)
|
'Event', self.test_appointment.calendar_event)
|
||||||
|
self.assertEqual(cal_event.starts_on,
|
||||||
|
self.test_appointment.scheduled_time)
|
||||||
|
|
||||||
def test_lead_linked(self):
|
def test_lead_linked(self):
|
||||||
lead = frappe.get_doc('Lead', self.test_lead.name)
|
lead = frappe.get_doc('Lead', self.test_lead.name)
|
||||||
|
|||||||
@ -211,7 +211,6 @@ async function submit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_form_data() {
|
function get_form_data() {
|
||||||
|
|
||||||
contact = {};
|
contact = {};
|
||||||
contact.name = document.getElementById('customer_name').value;
|
contact.name = document.getElementById('customer_name').value;
|
||||||
contact.number = document.getElementById('customer_number').value;
|
contact.number = document.getElementById('customer_number').value;
|
||||||
|
|||||||
@ -9,21 +9,26 @@ WEEKDAYS = ["Monday", "Tuesday", "Wednesday",
|
|||||||
|
|
||||||
no_cache = 1
|
no_cache = 1
|
||||||
|
|
||||||
|
|
||||||
def get_context(context):
|
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:
|
if is_enabled:
|
||||||
return context
|
return context
|
||||||
else:
|
else:
|
||||||
raise frappe.DoesNotExistError
|
raise frappe.DoesNotExistError
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def get_appointment_settings():
|
def get_appointment_settings():
|
||||||
settings = frappe.get_doc('Appointment Booking Settings')
|
settings = frappe.get_doc('Appointment Booking Settings')
|
||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def is_enabled():
|
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
|
return enable_scheduling
|
||||||
|
|
||||||
|
|
||||||
@ -131,15 +136,18 @@ def filter_timeslots(date, timeslots):
|
|||||||
filtered_timeslots.append(timeslot)
|
filtered_timeslots.append(timeslot)
|
||||||
return filtered_timeslots
|
return filtered_timeslots
|
||||||
|
|
||||||
|
|
||||||
def check_availabilty(timeslot, settings):
|
def check_availabilty(timeslot, settings):
|
||||||
return frappe.db.count('Appointment', {'scheduled_time': timeslot}) < settings.number_of_agents
|
return frappe.db.count('Appointment', {'scheduled_time': timeslot}) < settings.number_of_agents
|
||||||
|
|
||||||
|
|
||||||
def _is_holiday(date, holiday_list):
|
def _is_holiday(date, holiday_list):
|
||||||
for holiday in holiday_list.holidays:
|
for holiday in holiday_list.holidays:
|
||||||
if holiday.holiday_date == date:
|
if holiday.holiday_date == date:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _get_records(start_time, end_time, settings):
|
def _get_records(start_time, end_time, settings):
|
||||||
records = []
|
records = []
|
||||||
for record in settings.availability_of_slots:
|
for record in settings.availability_of_slots:
|
||||||
@ -147,10 +155,12 @@ def _get_records(start_time, end_time, settings):
|
|||||||
records.append(record)
|
records.append(record)
|
||||||
return records
|
return records
|
||||||
|
|
||||||
|
|
||||||
def _deltatime_to_datetime(date, deltatime):
|
def _deltatime_to_datetime(date, deltatime):
|
||||||
time = (datetime.datetime.min + deltatime).time()
|
time = (datetime.datetime.min + deltatime).time()
|
||||||
return datetime.datetime.combine(date.date(), time)
|
return datetime.datetime.combine(date.date(), time)
|
||||||
|
|
||||||
|
|
||||||
def _datetime_to_deltatime(date_time):
|
def _datetime_to_deltatime(date_time):
|
||||||
midnight = datetime.datetime.combine(date_time.date(), datetime.time.min)
|
midnight = datetime.datetime.combine(date_time.date(), datetime.time.min)
|
||||||
return (date_time-midnight)
|
return (date_time-midnight)
|
||||||
Loading…
x
Reference in New Issue
Block a user