feat:assign appointments from opportunity
This commit is contained in:
parent
c1bc0f9dfb
commit
bfe18d6085
@ -106,6 +106,16 @@ class Appointment(Document):
|
|||||||
self.lead = lead.name
|
self.lead = lead.name
|
||||||
|
|
||||||
def auto_assign(self):
|
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:
|
if self._assign:
|
||||||
return
|
return
|
||||||
available_agents = _get_agents_sorted_by_asc_workload(
|
available_agents = _get_agents_sorted_by_asc_workload(
|
||||||
@ -120,6 +130,25 @@ class Appointment(Document):
|
|||||||
})
|
})
|
||||||
break
|
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):
|
def create_calendar_event(self):
|
||||||
if self.calendar_event:
|
if self.calendar_event:
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user