feat:assign appointments from opportunity

This commit is contained in:
Pranav Nachanekar 2019-10-04 14:41:54 +05:30
parent c1bc0f9dfb
commit bfe18d6085

View File

@ -106,6 +106,16 @@ class Appointment(Document):
self.lead = lead.name
def auto_assign(self):
# If the latest opportunity is assigned to someone
# Assign the appointment to the same
existing_assignee = self.get_assignee_from_latest_opportunity()
if existing_assignee:
add_assignemnt({
'doctype':self.doctype
'name':self.name
'assign_to':existing_assignee
})
return
if self._assign:
return
available_agents = _get_agents_sorted_by_asc_workload(
@ -120,6 +130,25 @@ class Appointment(Document):
})
break
def get_assignee_from_latest_opportunity(self):
if not self.lead:
return None
if not frappe.db.exists('Lead', self.lead):
return None
opporutnities = frappe.get_list(
'Opportunity',
filters={
'party_name': self.lead,
},
order_by='creation desc')
latest_opportunity = frappe.get_doc(
'Opportunity', opporutnities[0].name)
assignee = latest_opportunity._assign
if not assignee:
return None
assignee = frappe.parse_json(assignee)[0]
return assignee
def create_calendar_event(self):
if self.calendar_event:
return