fix: share deal when deal_owner is changed
This commit is contained in:
parent
fd228544bf
commit
1e2b27594c
@ -20,6 +20,7 @@ class CRMDeal(Document):
|
|||||||
self.set_primary_email_mobile_no()
|
self.set_primary_email_mobile_no()
|
||||||
self.update_organization()
|
self.update_organization()
|
||||||
if self.deal_owner and not self.is_new():
|
if self.deal_owner and not self.is_new():
|
||||||
|
self.share_with_agent(self.deal_owner)
|
||||||
self.assign_agent(self.deal_owner)
|
self.assign_agent(self.deal_owner)
|
||||||
if self.has_value_changed("status"):
|
if self.has_value_changed("status"):
|
||||||
add_status_change_log(self)
|
add_status_change_log(self)
|
||||||
@ -95,6 +96,27 @@ class CRMDeal(Document):
|
|||||||
|
|
||||||
assign({"assign_to": [agent], "doctype": "CRM Deal", "name": self.name})
|
assign({"assign_to": [agent], "doctype": "CRM Deal", "name": self.name})
|
||||||
|
|
||||||
|
def share_with_agent(self, agent):
|
||||||
|
if not agent:
|
||||||
|
return
|
||||||
|
|
||||||
|
docshares = frappe.get_all(
|
||||||
|
"DocShare",
|
||||||
|
filters={"share_name": self.name, "share_doctype": self.doctype},
|
||||||
|
fields=["name", "user"],
|
||||||
|
)
|
||||||
|
|
||||||
|
shared_with = [d.user for d in docshares] + [agent]
|
||||||
|
|
||||||
|
for user in shared_with:
|
||||||
|
if user == agent and not frappe.db.exists("DocShare", {"user": agent, "share_name": self.name, "share_doctype": self.doctype}):
|
||||||
|
frappe.share.add_docshare(
|
||||||
|
self.doctype, self.name, agent, write=1, flags={"ignore_share_permission": True}
|
||||||
|
)
|
||||||
|
elif user != agent:
|
||||||
|
frappe.share.remove(self.doctype, self.name, user)
|
||||||
|
|
||||||
|
|
||||||
def set_sla(self):
|
def set_sla(self):
|
||||||
"""
|
"""
|
||||||
Find an SLA to apply to the deal.
|
Find an SLA to apply to the deal.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user