From 4802d719edf62e558b623b5dceaa75991df3a607 Mon Sep 17 00:00:00 2001 From: Daizy Modi Date: Fri, 16 Dec 2022 15:55:58 +0530 Subject: [PATCH] fix: removed unused data and minor changes --- .../crm/doctype/appointment/appointment.py | 19 +++++------- erpnext/www/book_appointment/index.js | 3 -- erpnext/www/book_appointment/index.py | 30 ++++++++----------- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/erpnext/crm/doctype/appointment/appointment.py b/erpnext/crm/doctype/appointment/appointment.py index a4e00d6c47b..bd49bdc925c 100644 --- a/erpnext/crm/doctype/appointment/appointment.py +++ b/erpnext/crm/doctype/appointment/appointment.py @@ -136,15 +136,14 @@ class Appointment(Document): if existing_assignee: # If the latest opportunity is assigned to someone # Assign the appointment to the same - assign_agents(self.doctype, self.name, [existing_assignee]) + self.assign_agent(existing_assignee) return if self._assign: return available_agents = _get_agents_sorted_by_asc_workload(getdate(self.scheduled_time)) for agent in available_agents: if _check_agent_availability(agent, self.scheduled_time): - agent = agent[0] - assign_agents(self.doctype, self.name, [agent]) + self.assign_agent(agent[0]) break def get_assignee_from_latest_opportunity(self): @@ -199,6 +198,12 @@ class Appointment(Document): params = {"email": self.customer_email, "appointment": self.name} 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): appointments = frappe.get_all("Appointment", fields="*") @@ -240,11 +245,3 @@ def _get_employee_from_user(user): if employee_docname: return frappe.get_doc("Employee", employee_docname) 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}) diff --git a/erpnext/www/book_appointment/index.js b/erpnext/www/book_appointment/index.js index 46ac15518c7..d02cdad4cf4 100644 --- a/erpnext/www/book_appointment/index.js +++ b/erpnext/www/book_appointment/index.js @@ -2,8 +2,6 @@ frappe.ready(async () => { initialise_select_date(); }) -window.holiday_list = []; - async function initialise_select_date() { navigate_to_page(1); await get_global_variables(); @@ -20,7 +18,6 @@ async function get_global_variables() { window.timezones = (await frappe.call({ method:'erpnext.www.book_appointment.index.get_timezones' })).message; - window.holiday_list = window.appointment_settings.holiday_list; } function setup_timezone_selector() { diff --git a/erpnext/www/book_appointment/index.py b/erpnext/www/book_appointment/index.py index 8cb66275e05..dfca9465ed1 100644 --- a/erpnext/www/book_appointment/index.py +++ b/erpnext/www/book_appointment/index.py @@ -29,7 +29,7 @@ def get_appointment_settings(): settings = frappe.get_cached_value( "Appointment Booking Settings", None, - ["holiday_list", "advance_booking_days", "appointment_duration", "success_redirect_url"], + ["advance_booking_days", "appointment_duration", "success_redirect_url"], as_dict=True, ) return settings @@ -94,26 +94,22 @@ def get_available_slots_between(query_start_time, query_end_time, settings): @frappe.whitelist(allow_guest=True) def create_appointment(date, time, tz, contact): - contact = json.loads(contact) - datetime_obj = datetime.datetime.strptime(date + " " + time, "%Y-%m-%d %H:%M:%S") + format_string = "%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 - 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.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.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(ignore_permissions=True) return appointment