fix: removed unused data and minor changes

This commit is contained in:
Daizy Modi 2022-12-16 15:55:58 +05:30
parent 5d0b5c8d2a
commit 4802d719ed
3 changed files with 21 additions and 31 deletions

View File

@ -136,15 +136,14 @@ class Appointment(Document):
if existing_assignee: if existing_assignee:
# If the latest opportunity is assigned to someone # If the latest opportunity is assigned to someone
# Assign the appointment to the same # Assign the appointment to the same
assign_agents(self.doctype, self.name, [existing_assignee]) self.assign_agent(existing_assignee)
return return
if self._assign: if self._assign:
return return
available_agents = _get_agents_sorted_by_asc_workload(getdate(self.scheduled_time)) available_agents = _get_agents_sorted_by_asc_workload(getdate(self.scheduled_time))
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] self.assign_agent(agent[0])
assign_agents(self.doctype, self.name, [agent])
break break
def get_assignee_from_latest_opportunity(self): def get_assignee_from_latest_opportunity(self):
@ -199,6 +198,12 @@ class Appointment(Document):
params = {"email": self.customer_email, "appointment": self.name} params = {"email": self.customer_email, "appointment": self.name}
return get_url(verify_route + "?" + get_signed_params(params)) return get_url(verify_route + "?" + get_signed_params(params))
def assign_agent(self, agent):
if not frappe.has_permission(doc=self, user=agent):
add_docshare(self.doctype, self.name, agent, flags={"ignore_share_permission": True})
add_assignment({"doctype": self.doctype, "name": self.name, "assign_to": [agent]})
def _get_agents_sorted_by_asc_workload(date): def _get_agents_sorted_by_asc_workload(date):
appointments = frappe.get_all("Appointment", fields="*") appointments = frappe.get_all("Appointment", fields="*")
@ -240,11 +245,3 @@ def _get_employee_from_user(user):
if employee_docname: if employee_docname:
return frappe.get_doc("Employee", employee_docname) return frappe.get_doc("Employee", employee_docname)
return None return None
def assign_agents(doctype: str, name: str, agents: list[str]) -> None:
for agent in agents:
if not frappe.has_permission(doctype=doctype, doc=name, user=agent):
add_docshare(doctype, name, agent, flags={"ignore_share_permission": True})
add_assignment({"doctype": doctype, "name": name, "assign_to": agents})

View File

@ -2,8 +2,6 @@ frappe.ready(async () => {
initialise_select_date(); initialise_select_date();
}) })
window.holiday_list = [];
async function initialise_select_date() { async function initialise_select_date() {
navigate_to_page(1); navigate_to_page(1);
await get_global_variables(); await get_global_variables();
@ -20,7 +18,6 @@ async function get_global_variables() {
window.timezones = (await frappe.call({ window.timezones = (await frappe.call({
method:'erpnext.www.book_appointment.index.get_timezones' method:'erpnext.www.book_appointment.index.get_timezones'
})).message; })).message;
window.holiday_list = window.appointment_settings.holiday_list;
} }
function setup_timezone_selector() { function setup_timezone_selector() {

View File

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