fix: fetch required details from appointment booking settings

This commit is contained in:
Daizy Modi 2022-12-15 16:53:51 +05:30
parent 9a00b3bdbd
commit ac51c27500
2 changed files with 24 additions and 18 deletions

View File

@ -26,8 +26,12 @@ def get_context(context):
@frappe.whitelist(allow_guest=True)
def get_appointment_settings():
settings = frappe.get_doc("Appointment Booking Settings")
settings.holiday_list = frappe.get_doc("Holiday List", settings.holiday_list)
settings = frappe.get_cached_value(
"Appointment Booking Settings",
None,
["holiday_list", "advance_booking_days", "appointment_duration", "success_redirect_url"],
as_dict=True,
)
return settings
@ -90,23 +94,27 @@ def get_available_slots_between(query_start_time, query_end_time, settings):
@frappe.whitelist(allow_guest=True)
def create_appointment(date, time, tz, contact):
format_string = "%Y-%m-%d %H:%M:%S"
scheduled_time = datetime.datetime.strptime(date + " " + time, format_string)
contact = json.loads(contact)
datetime_obj = datetime.datetime.strptime(date + " " + time, "%Y-%m-%d %H:%M:%S")
# Strip tzinfo from datetime objects since it's handled by the doctype
scheduled_time_obj = datetime_obj.replace(tzinfo=None)
scheduled_time = convert_to_system_timezone(tz, scheduled_time_obj)
scheduled_time = scheduled_time.replace(tzinfo=None)
scheduled_time = convert_to_system_timezone(tz, scheduled_time)
scheduled_time = scheduled_time.replace(tzinfo=None)
# Create a appointment document from form
appointment = frappe.new_doc("Appointment")
appointment.scheduled_time = scheduled_time
contact = json.loads(contact)
appointment.customer_name = contact.get("name", None)
appointment.customer_phone_number = contact.get("number", None)
appointment.customer_skype = contact.get("skype", None)
appointment.customer_details = contact.get("notes", None)
appointment.customer_email = contact.get("email", None)
appointment.status = "Open"
appointment.insert()
appointment.update(
{
"scheduled_time": scheduled_time,
"customer_name": contact.get("name", None),
"customer_phone_number": contact.get("number", None),
"customer_skype": contact.get("skype", None),
"customer_details": contact.get("notes", None),
"customer_email": contact.get("email", None),
"status": "Open",
}
)
appointment.insert(ignore_permissions=True)
return appointment

View File

@ -2,7 +2,6 @@ import frappe
from frappe.utils.verified_command import verify_request
@frappe.whitelist(allow_guest=True)
def get_context(context):
if not verify_request():
context.success = False
@ -15,7 +14,6 @@ def get_context(context):
appointment = frappe.get_doc("Appointment", appointment_name)
appointment.set_verified(email)
context.success = True
return context
else:
context.success = False
return context
return context