feat: carry forward communication and comments throughout the sales cycle

This commit is contained in:
Anupam 2021-11-19 10:13:05 +05:30
parent d0c240ee84
commit 6eb779392e
4 changed files with 44 additions and 0 deletions

View File

@ -12,6 +12,7 @@ from frappe.utils import cint, cstr, flt, get_fullname
from erpnext.setup.utils import get_exchange_rate
from erpnext.utilities.transaction_base import TransactionBase
from erpnext.crm.utils import copy_comments, add_link_in_communication
class Opportunity(TransactionBase):
@ -19,6 +20,10 @@ class Opportunity(TransactionBase):
if self.opportunity_from == "Lead":
frappe.get_doc("Lead", self.party_name).set_status(update=True)
if self.opportunity_from in ["Lead", "Prospect"]:
copy_comments(self.opportunity_from, self.party_name, self)
add_link_in_communication(self.opportunity_from, self.party_name, self)
def validate(self):
self._prev = frappe._dict({
"contact_date": frappe.db.get_value("Opportunity", self.name, "contact_date") if \

View File

@ -6,6 +6,8 @@ from frappe.contacts.address_and_contact import load_address_and_contact
from frappe.model.document import Document
from frappe.model.mapper import get_mapped_doc
from erpnext.crm.utils import copy_comments, add_link_in_communication
class Prospect(Document):
def onload(self):
@ -20,6 +22,11 @@ class Prospect(Document):
def on_trash(self):
self.unlink_dynamic_links()
def after_insert(self):
for row in self.get('prospect_lead'):
copy_comments("Lead", row.lead, self)
add_link_in_communication("Lead", row.lead, self)
def update_lead_details(self):
for row in self.get('prospect_lead'):
lead = frappe.get_value('Lead', row.lead, ['lead_name', 'status', 'email_id', 'mobile_no'], as_dict=True)

View File

@ -21,3 +21,25 @@ def update_lead_phone_numbers(contact, method):
lead = frappe.get_doc("Lead", contact_lead)
lead.db_set("phone", phone)
lead.db_set("mobile_no", mobile_no)
def copy_comments(doctype, docname, doc):
comments = frappe.db.get_values("Comment", filters={"reference_doctype": doctype, "reference_name": docname}, fieldname="*")
for comment in comments:
comment = frappe.get_doc(comment.update({"doctype":"Comment"}))
comment.name = None
comment.reference_doctype = doc.doctype
comment.reference_name = doc.name
comment.insert()
def add_link_in_communication(doctype, docname, doc):
communications = frappe.get_all("Communication", filters={"reference_doctype": doctype, "reference_name": docname}, pluck='name')
communication_links = frappe.get_all('Communication Link',
{
"link_doctype": doctype,
"link_name": docname,
"parent": ("not in", communications)
}, pluck="parent")
for communication in communications + communication_links:
communication_doc = frappe.get_doc("Communication", communication)
communication_doc.add_link(doc.doctype, doc.name, autosave=True)

View File

@ -8,6 +8,7 @@ from frappe.model.mapper import get_mapped_doc
from frappe.utils import flt, getdate, nowdate
from erpnext.controllers.selling_controller import SellingController
from erpnext.crm.utils import copy_comments, add_link_in_communication
form_grid_templates = {
"items": "templates/form_grid/item_grid.html"
@ -34,6 +35,15 @@ class Quotation(SellingController):
from erpnext.stock.doctype.packed_item.packed_item import make_packing_list
make_packing_list(self)
def after_insert(self):
if self.opportunity:
copy_comments("Opportunity", self.opportunity, self)
add_link_in_communication("Opportunity", self.opportunity, self)
elif self.quotation_to == "Lead" and self.party_name:
copy_comments("Lead", self.party_name, self)
add_link_in_communication("Lead", self.party_name, self)
def validate_valid_till(self):
if self.valid_till and getdate(self.valid_till) < getdate(self.transaction_date):
frappe.throw(_("Valid till date cannot be before transaction date"))