fix: auto add assignee if lead_owner or deal_owner is set
This commit is contained in:
parent
cb9a11cbda
commit
bca741c8bc
@ -27,4 +27,5 @@ def get_deal(name):
|
|||||||
)
|
)
|
||||||
|
|
||||||
deal["doctype_fields"] = get_doctype_fields("CRM Deal")
|
deal["doctype_fields"] = get_doctype_fields("CRM Deal")
|
||||||
|
deal["doctype"] = "CRM Deal"
|
||||||
return deal
|
return deal
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
import json
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
from frappe.desk.form.assign_to import add as assign
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
from crm.fcrm.doctype.crm_service_level_agreement.utils import get_sla
|
from crm.fcrm.doctype.crm_service_level_agreement.utils import get_sla
|
||||||
@ -15,6 +17,12 @@ class CRMDeal(Document):
|
|||||||
def validate(self):
|
def validate(self):
|
||||||
self.set_primary_contact()
|
self.set_primary_contact()
|
||||||
self.set_primary_email_mobile_no()
|
self.set_primary_email_mobile_no()
|
||||||
|
if self.deal_owner and not self.is_new():
|
||||||
|
self.assign_agent(self.deal_owner)
|
||||||
|
|
||||||
|
def after_insert(self):
|
||||||
|
if self.deal_owner:
|
||||||
|
self.assign_agent(self.deal_owner)
|
||||||
|
|
||||||
def before_save(self):
|
def before_save(self):
|
||||||
self.apply_sla()
|
self.apply_sla()
|
||||||
@ -53,6 +61,19 @@ class CRMDeal(Document):
|
|||||||
self.email = ""
|
self.email = ""
|
||||||
self.mobile_no = ""
|
self.mobile_no = ""
|
||||||
|
|
||||||
|
def assign_agent(self, agent):
|
||||||
|
if not agent:
|
||||||
|
return
|
||||||
|
|
||||||
|
if self._assign:
|
||||||
|
assignees = json.loads(self._assign)
|
||||||
|
for assignee in assignees:
|
||||||
|
if agent == assignee:
|
||||||
|
# the agent is already set as an assignee
|
||||||
|
return
|
||||||
|
|
||||||
|
assign({"assign_to": [agent], "doctype": "CRM Deal", "name": self.name})
|
||||||
|
|
||||||
def set_sla(self):
|
def set_sla(self):
|
||||||
"""
|
"""
|
||||||
Find an SLA to apply to the deal.
|
Find an SLA to apply to the deal.
|
||||||
|
|||||||
@ -15,4 +15,5 @@ def get_lead(name):
|
|||||||
lead = lead.pop()
|
lead = lead.pop()
|
||||||
|
|
||||||
lead["doctype_fields"] = get_doctype_fields("CRM Lead")
|
lead["doctype_fields"] = get_doctype_fields("CRM Lead")
|
||||||
|
lead["doctype"] = "CRM Lead"
|
||||||
return lead
|
return lead
|
||||||
@ -1,8 +1,10 @@
|
|||||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
import json
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
from frappe.desk.form.assign_to import add as assign
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
from frappe.utils import has_gravatar, validate_email_address
|
from frappe.utils import has_gravatar, validate_email_address
|
||||||
@ -18,6 +20,12 @@ class CRMLead(Document):
|
|||||||
self.set_lead_name()
|
self.set_lead_name()
|
||||||
self.set_title()
|
self.set_title()
|
||||||
self.validate_email()
|
self.validate_email()
|
||||||
|
if self.lead_owner and not self.is_new():
|
||||||
|
self.assign_agent(self.lead_owner)
|
||||||
|
|
||||||
|
def after_insert(self):
|
||||||
|
if self.lead_owner:
|
||||||
|
self.assign_agent(self.lead_owner)
|
||||||
|
|
||||||
def before_save(self):
|
def before_save(self):
|
||||||
self.apply_sla()
|
self.apply_sla()
|
||||||
@ -54,6 +62,19 @@ class CRMLead(Document):
|
|||||||
if self.is_new() or not self.image:
|
if self.is_new() or not self.image:
|
||||||
self.image = has_gravatar(self.email)
|
self.image = has_gravatar(self.email)
|
||||||
|
|
||||||
|
def assign_agent(self, agent):
|
||||||
|
if not agent:
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.get("_assign"):
|
||||||
|
assignees = json.loads(self._assign)
|
||||||
|
for assignee in assignees:
|
||||||
|
if agent == assignee:
|
||||||
|
# the agent is already set as an assignee
|
||||||
|
return
|
||||||
|
|
||||||
|
assign({"assign_to": [agent], "doctype": "CRM Lead", "name": self.name})
|
||||||
|
|
||||||
def create_contact(self, throw=True):
|
def create_contact(self, throw=True):
|
||||||
if not self.lead_name:
|
if not self.lead_name:
|
||||||
self.set_full_name()
|
self.set_full_name()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user