mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 19:29:10 +00:00
Formatting
This commit is contained in:
@@ -6,5 +6,6 @@ from __future__ import unicode_literals
|
|||||||
# import frappe
|
# import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|
||||||
class AvailabilityOfSlots(Document):
|
class AvailabilityOfSlots(Document):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
{% block title %}{{ _("Book Appointment") }}{% endblock %}
|
{% block title %}{{ _("Book Appointment") }}{% endblock %}
|
||||||
|
|
||||||
{% block script %}
|
{% block script %}
|
||||||
<script src="assets/js/moment-bundle.min.js"></script>
|
<script src="assets/js/moment-bundle.min.js"></script>
|
||||||
<script src="book-appointment/index.js"></script>
|
<script src="book-appointment/index.js"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block page_content %}
|
{% block page_content %}
|
||||||
@@ -18,15 +18,16 @@
|
|||||||
<div class="row justify-content-center mt-3">
|
<div class="row justify-content-center mt-3">
|
||||||
<div class="col-md-6 align-self-center ">
|
<div class="col-md-6 align-self-center ">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<input type="date" oninput="on_date_or_timezone_select()" name="appointment-date" id="appointment-date"
|
<input type="date" oninput="on_date_or_timezone_select()" name="appointment-date"
|
||||||
class="form-control mt-3 col-md m-3">
|
id="appointment-date" class="form-control mt-3 col-md m-3">
|
||||||
<select name="appointment-timezone" oninput="on_date_or_timezone_select()" id="appointment-timezone" class="form-control mt-3 col-md">
|
<select name="appointment-timezone" oninput="on_date_or_timezone_select()" id="appointment-timezone"
|
||||||
|
class="form-control mt-3 col-md">
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mt-3" id="timeslot-container" >
|
<div class="row mt-3" id="timeslot-container">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row justify-content-center mt-3">
|
<div class="row justify-content-center mt-3">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
|
|||||||
@@ -4,50 +4,62 @@ import json
|
|||||||
|
|
||||||
no_cache = 1
|
no_cache = 1
|
||||||
|
|
||||||
|
|
||||||
@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 get_holiday_list(holiday_list_name):
|
def get_holiday_list(holiday_list_name):
|
||||||
holiday_list = frappe.get_doc('Holiday List',holiday_list_name)
|
holiday_list = frappe.get_doc('Holiday List', holiday_list_name)
|
||||||
return holiday_list
|
return holiday_list
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def get_timezones():
|
def get_timezones():
|
||||||
timezones = frappe.get_list('Timezone',fields='*')
|
timezones = frappe.get_list('Timezone', fields='*')
|
||||||
return timezones
|
return timezones
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def get_appointment_slots(date,timezone):
|
def get_appointment_slots(date, timezone):
|
||||||
timezone = int(timezone)
|
timezone = int(timezone)
|
||||||
format_string = '%Y-%m-%d %H:%M:%S'
|
format_string = '%Y-%m-%d %H:%M:%S'
|
||||||
query_start_time = datetime.datetime.strptime(date + ' 00:00:00',format_string)
|
query_start_time = datetime.datetime.strptime(
|
||||||
query_end_time = datetime.datetime.strptime(date + ' 23:59:59',format_string)
|
date + ' 00:00:00', format_string)
|
||||||
query_start_time = _convert_to_ist(query_start_time,timezone)
|
query_end_time = datetime.datetime.strptime(
|
||||||
query_end_time = _convert_to_ist(query_end_time,timezone)
|
date + ' 23:59:59', format_string)
|
||||||
|
query_start_time = _convert_to_ist(query_start_time, timezone)
|
||||||
|
query_end_time = _convert_to_ist(query_end_time, timezone)
|
||||||
# Database queries
|
# Database queries
|
||||||
settings = frappe.get_doc('Appointment Booking Settings')
|
settings = frappe.get_doc('Appointment Booking Settings')
|
||||||
holiday_list = frappe.get_doc('Holiday List', settings.holiday_list)
|
holiday_list = frappe.get_doc('Holiday List', settings.holiday_list)
|
||||||
timeslots = get_available_slots_between(query_start_time, query_end_time, settings)
|
timeslots = get_available_slots_between(
|
||||||
|
query_start_time, query_end_time, settings)
|
||||||
|
|
||||||
# Filter timeslots based on date
|
# Filter timeslots based on date
|
||||||
converted_timeslots = []
|
converted_timeslots = []
|
||||||
for timeslot in timeslots:
|
for timeslot in timeslots:
|
||||||
# Check if holiday
|
# Check if holiday
|
||||||
if _is_holiday(timeslot.date(),holiday_list):
|
if _is_holiday(timeslot.date(), holiday_list):
|
||||||
converted_timeslots.append(dict(time=_convert_to_tz(timeslot,timezone),availability=False))
|
converted_timeslots.append(
|
||||||
|
dict(time=_convert_to_tz(timeslot, timezone), availability=False))
|
||||||
continue
|
continue
|
||||||
# Check availability
|
# Check availability
|
||||||
if check_availabilty(timeslot,settings):
|
if check_availabilty(timeslot, settings):
|
||||||
converted_timeslots.append(dict(time=_convert_to_tz(timeslot,timezone),availability=True))
|
converted_timeslots.append(
|
||||||
|
dict(time=_convert_to_tz(timeslot, timezone), availability=True))
|
||||||
else:
|
else:
|
||||||
converted_timeslots.append(dict(time=_convert_to_tz(timeslot,timezone),availability=False))
|
converted_timeslots.append(
|
||||||
date_required = datetime.datetime.strptime(date + ' 00:00:00',format_string).date()
|
dict(time=_convert_to_tz(timeslot, timezone), availability=False))
|
||||||
converted_timeslots = filter_timeslots(date_required,converted_timeslots)
|
date_required = datetime.datetime.strptime(
|
||||||
|
date + ' 00:00:00', format_string).date()
|
||||||
|
converted_timeslots = filter_timeslots(date_required, converted_timeslots)
|
||||||
return converted_timeslots
|
return converted_timeslots
|
||||||
|
|
||||||
|
|
||||||
def get_available_slots_between(query_start_time, query_end_time, settings):
|
def get_available_slots_between(query_start_time, query_end_time, settings):
|
||||||
records = _get_records(query_start_time, query_end_time, settings)
|
records = _get_records(query_start_time, query_end_time, settings)
|
||||||
timeslots = []
|
timeslots = []
|
||||||
@@ -59,7 +71,7 @@ def get_available_slots_between(query_start_time, query_end_time, settings):
|
|||||||
query_start_time, record.from_time)
|
query_start_time, record.from_time)
|
||||||
end_time = _deltatime_to_datetime(
|
end_time = _deltatime_to_datetime(
|
||||||
query_start_time, record.to_time)
|
query_start_time, record.to_time)
|
||||||
else :
|
else:
|
||||||
current_time = _deltatime_to_datetime(
|
current_time = _deltatime_to_datetime(
|
||||||
query_end_time, record.from_time)
|
query_end_time, record.from_time)
|
||||||
end_time = _deltatime_to_datetime(
|
end_time = _deltatime_to_datetime(
|
||||||
@@ -69,11 +81,13 @@ def get_available_slots_between(query_start_time, query_end_time, settings):
|
|||||||
current_time += appointment_duration
|
current_time += appointment_duration
|
||||||
return timeslots
|
return timeslots
|
||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
|
||||||
def create_appointment(date,time,contact):
|
@frappe.whitelist(allow_guest=True)
|
||||||
|
def create_appointment(date, time, contact):
|
||||||
appointment = frappe.new_doc('Appointment')
|
appointment = frappe.new_doc('Appointment')
|
||||||
format_string = '%Y-%m-%d %H:%M:%S'
|
format_string = '%Y-%m-%d %H:%M:%S'
|
||||||
appointment.scheduled_time = datetime.datetime.strptime(date+" "+time,format_string)
|
appointment.scheduled_time = datetime.datetime.strptime(
|
||||||
|
date+" "+time, format_string)
|
||||||
contact = json.loads(contact)
|
contact = json.loads(contact)
|
||||||
appointment.customer_name = contact['name']
|
appointment.customer_name = contact['name']
|
||||||
appointment.customer_phone_number = contact['number']
|
appointment.customer_phone_number = contact['number']
|
||||||
@@ -83,15 +97,17 @@ def create_appointment(date,time,contact):
|
|||||||
|
|
||||||
|
|
||||||
# Helper Functions
|
# Helper Functions
|
||||||
def filter_timeslots(date,timeslots):
|
def filter_timeslots(date, timeslots):
|
||||||
filtered_timeslots = []
|
filtered_timeslots = []
|
||||||
for timeslot in timeslots:
|
for timeslot in timeslots:
|
||||||
if(timeslot['time'].date() == date):
|
if(timeslot['time'].date() == date):
|
||||||
filtered_timeslots.append(timeslot)
|
filtered_timeslots.append(timeslot)
|
||||||
return filtered_timeslots
|
return filtered_timeslots
|
||||||
|
|
||||||
def check_availabilty(timeslot,settings):
|
|
||||||
return frappe.db.count('Appointment',{'scheduled_time':timeslot})<settings.number_of_agents
|
def check_availabilty(timeslot, settings):
|
||||||
|
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:
|
||||||
@@ -99,6 +115,7 @@ def _is_holiday(date, holiday_list):
|
|||||||
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:
|
||||||
@@ -106,14 +123,17 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
def _convert_to_ist(datetime_object, timezone):
|
def _convert_to_ist(datetime_object, timezone):
|
||||||
offset = datetime.timedelta(minutes=timezone)
|
offset = datetime.timedelta(minutes=timezone)
|
||||||
datetime_object = datetime_object + offset
|
datetime_object = datetime_object + offset
|
||||||
@@ -121,6 +141,7 @@ def _convert_to_ist(datetime_object, timezone):
|
|||||||
datetime_object = datetime_object - offset
|
datetime_object = datetime_object - offset
|
||||||
return datetime_object
|
return datetime_object
|
||||||
|
|
||||||
|
|
||||||
def _convert_to_tz(datetime_object, timezone):
|
def _convert_to_tz(datetime_object, timezone):
|
||||||
offset = datetime.timedelta(minutes=timezone)
|
offset = datetime.timedelta(minutes=timezone)
|
||||||
datetime_object = datetime_object - offset
|
datetime_object = datetime_object - offset
|
||||||
@@ -128,5 +149,6 @@ def _convert_to_tz(datetime_object, timezone):
|
|||||||
datetime_object = datetime_object + offset
|
datetime_object = datetime_object + offset
|
||||||
return datetime_object
|
return datetime_object
|
||||||
|
|
||||||
|
|
||||||
WEEKDAYS = ["Monday", "Tuesday", "Wednesday",
|
WEEKDAYS = ["Monday", "Tuesday", "Wednesday",
|
||||||
"Thursday", "Friday", "Saturday", "Sunday"]
|
"Thursday", "Friday", "Saturday", "Sunday"]
|
||||||
|
|||||||
Reference in New Issue
Block a user