mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-21 05:59:18 +00:00
limit assigment load to appointment day
This commit is contained in:
@@ -21,6 +21,9 @@ class Appointment(Document):
|
|||||||
|
|
||||||
def before_insert(self):
|
def before_insert(self):
|
||||||
self.lead = _find_lead_by_email(self.lead).name
|
self.lead = _find_lead_by_email(self.lead).name
|
||||||
|
|
||||||
|
|
||||||
|
def after_insert(self):
|
||||||
appointment_event = frappe.get_doc({
|
appointment_event = frappe.get_doc({
|
||||||
'doctype': 'Event',
|
'doctype': 'Event',
|
||||||
'subject': ' '.join(['Appointment with', self.customer_name]),
|
'subject': ' '.join(['Appointment with', self.customer_name]),
|
||||||
@@ -31,9 +34,7 @@ class Appointment(Document):
|
|||||||
})
|
})
|
||||||
appointment_event.insert(ignore_permissions=True)
|
appointment_event.insert(ignore_permissions=True)
|
||||||
self.calendar_event = appointment_event.name
|
self.calendar_event = appointment_event.name
|
||||||
|
available_agents = _get_agents_sorted_by_asc_workload(self.scheduled_time.date())
|
||||||
def after_insert(self):
|
|
||||||
available_agents = _get_agents_sorted_by_asc_workload()
|
|
||||||
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]
|
agent = agent[0]
|
||||||
@@ -51,7 +52,7 @@ class Appointment(Document):
|
|||||||
calendar_event.save()
|
calendar_event.save()
|
||||||
break
|
break
|
||||||
|
|
||||||
def _get_agents_sorted_by_asc_workload():
|
def _get_agents_sorted_by_asc_workload(date):
|
||||||
appointments = frappe.db.get_list('Appointment', fields='*')
|
appointments = frappe.db.get_list('Appointment', fields='*')
|
||||||
agent_list = _get_agent_list_as_strings()
|
agent_list = _get_agent_list_as_strings()
|
||||||
if not appointments:
|
if not appointments:
|
||||||
@@ -61,7 +62,7 @@ def _get_agents_sorted_by_asc_workload():
|
|||||||
assigned_to = frappe.parse_json(appointment._assign)
|
assigned_to = frappe.parse_json(appointment._assign)
|
||||||
if not assigned_to:
|
if not assigned_to:
|
||||||
continue
|
continue
|
||||||
if assigned_to[0] in agent_list:
|
if (assigned_to[0] in agent_list) and appointment.scheduled_time.date() == date:
|
||||||
appointment_counter[assigned_to[0]] += 1
|
appointment_counter[assigned_to[0]] += 1
|
||||||
sorted_agent_list = appointment_counter.most_common()
|
sorted_agent_list = appointment_counter.most_common()
|
||||||
sorted_agent_list.reverse()
|
sorted_agent_list.reverse()
|
||||||
@@ -69,7 +70,7 @@ def _get_agents_sorted_by_asc_workload():
|
|||||||
return sorted_agent_list
|
return sorted_agent_list
|
||||||
|
|
||||||
def _find_lead_by_email(email):
|
def _find_lead_by_email(email):
|
||||||
lead_list = frappe.get_list('Lead',filters={'email_id':email},ignore_permissions=True)
|
lead_list = frappe.get_list('Lead', filters={'email_id':email}, ignore_permissions=True)
|
||||||
if lead_list:
|
if lead_list:
|
||||||
return lead_list[0]
|
return lead_list[0]
|
||||||
frappe.throw('Email ID not associated with any Lead. Please make sure to use the email address you got this mail on')
|
frappe.throw('Email ID not associated with any Lead. Please make sure to use the email address you got this mail on')
|
||||||
@@ -92,7 +93,7 @@ def _check_agent_availability(agent_email,scheduled_time):
|
|||||||
|
|
||||||
|
|
||||||
def _get_employee_from_user(user):
|
def _get_employee_from_user(user):
|
||||||
employee_docname = frappe.db.exists({'doctype':'Employee','user_id':user})
|
employee_docname = frappe.db.exists({'doctype':'Employee', 'user_id':user})
|
||||||
if employee_docname:
|
if employee_docname:
|
||||||
return frappe.get_doc('Employee',employee_docname[0][0]) # frappe.db.exists returns a tuple of a tuple
|
return frappe.get_doc('Employee', employee_docname[0][0]) # frappe.db.exists returns a tuple of a tuple
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user