feat: link lead communication to prospect
This commit is contained in:
parent
3610882077
commit
0c6212189e
@ -362,3 +362,13 @@ def daily_open_lead():
|
||||
leads = frappe.get_all("Lead", filters = [["contact_date", "Between", [nowdate(), nowdate()]]])
|
||||
for lead in leads:
|
||||
frappe.db.set_value("Lead", lead.name, "status", "Open")
|
||||
|
||||
def add_prospect_link_in_communication(communication, method):
|
||||
if communication.get('reference_doctype') == "Lead":
|
||||
links = frappe.get_all('Prospect Lead', filters={'lead': communication.get('reference_name')}, fields=['parent', 'parenttype'])
|
||||
|
||||
for link in links:
|
||||
communication.append('timeline_links', {
|
||||
'link_doctype': link['parenttype'],
|
||||
'link_name': link['parent']
|
||||
})
|
||||
|
@ -6,9 +6,12 @@ from frappe.model.document import Document
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
class Prospect(Document):
|
||||
def validate(self):
|
||||
def after_save(self):
|
||||
self.link_with_lead_contact_and_address()
|
||||
|
||||
def on_trash(self):
|
||||
self.unlink_dynamic_links()
|
||||
|
||||
def link_with_lead_contact_and_address(self):
|
||||
for row in self.prospect_lead:
|
||||
links = frappe.get_all('Dynamic Link', filters={'link_doctype': 'Lead', 'link_name': row.lead}, fields=['parent', 'parenttype'])
|
||||
@ -27,6 +30,23 @@ class Prospect(Document):
|
||||
})
|
||||
linked_doc.save(ignore_permissions=True)
|
||||
|
||||
def unlink_dynamic_links(self):
|
||||
links = frappe.get_all('Dynamic Link', filters={'link_doctype': self.doctype, 'link_name': self.name}, fields=['parent', 'parenttype'])
|
||||
|
||||
for link in links:
|
||||
linked_doc = frappe.get_doc(link['parenttype'], link['parent'])
|
||||
|
||||
if len(linked_doc.get('links')) == 1:
|
||||
linked_doc.delete(ignore_permissions=True)
|
||||
else:
|
||||
to_remove = None
|
||||
for d in linked_doc.get('links'):
|
||||
if d.link_doctype == self.doctype and d.link_name == self.name:
|
||||
to_remove = d
|
||||
if to_remove:
|
||||
linked_doc.remove(to_remove)
|
||||
linked_doc.save(ignore_permissions=True)
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_customer(source_name, target_doc=None):
|
||||
def set_missing_values(source, target):
|
||||
|
@ -249,6 +249,9 @@ doc_events = {
|
||||
"on_update": [
|
||||
"erpnext.support.doctype.service_level_agreement.service_level_agreement.update_hold_time",
|
||||
"erpnext.support.doctype.issue.issue.set_first_response_time"
|
||||
],
|
||||
"after_insert": [
|
||||
"erpnext.crm.doctype.lead.lead.add_prospect_link_in_communication"
|
||||
]
|
||||
},
|
||||
("Sales Taxes and Charges Template", 'Price List'): {
|
||||
|
Loading…
x
Reference in New Issue
Block a user