fix: fetch required details from appointment booking settings
diff --git a/erpnext/www/book_appointment/index.py b/erpnext/www/book_appointment/index.py
index 06e99da..8cb6627 100644
--- a/erpnext/www/book_appointment/index.py
+++ b/erpnext/www/book_appointment/index.py
@@ -26,8 +26,12 @@
@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 @@
@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
diff --git a/erpnext/www/book_appointment/verify/index.py b/erpnext/www/book_appointment/verify/index.py
index 1a5ba9d..4a1ed75 100644
--- a/erpnext/www/book_appointment/verify/index.py
+++ b/erpnext/www/book_appointment/verify/index.py
@@ -2,7 +2,6 @@
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 @@
appointment = frappe.get_doc("Appointment", appointment_name)
appointment.set_verified(email)
context.success = True
- return context
else:
context.success = False
- return context
+ return context