From 6eb779392edaca95e5d90e610246164524e17b36 Mon Sep 17 00:00:00 2001 From: Anupam Date: Fri, 19 Nov 2021 10:13:05 +0530 Subject: [PATCH 01/11] feat: carry forward communication and comments throughout the sales cycle --- .../crm/doctype/opportunity/opportunity.py | 5 +++++ erpnext/crm/doctype/prospect/prospect.py | 7 ++++++ erpnext/crm/utils.py | 22 +++++++++++++++++++ .../selling/doctype/quotation/quotation.py | 10 +++++++++ 4 files changed, 44 insertions(+) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 0bef80a749..d565ad2f2c 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -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 \ diff --git a/erpnext/crm/doctype/prospect/prospect.py b/erpnext/crm/doctype/prospect/prospect.py index 367aa3d312..736b3dfdd5 100644 --- a/erpnext/crm/doctype/prospect/prospect.py +++ b/erpnext/crm/doctype/prospect/prospect.py @@ -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) diff --git a/erpnext/crm/utils.py b/erpnext/crm/utils.py index 95b19ec21e..531d6c1594 100644 --- a/erpnext/crm/utils.py +++ b/erpnext/crm/utils.py @@ -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) diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index c4752aebb5..adea9ec406 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -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")) From 6dda1548bc021f15b54db2efc43bd8905eac59d8 Mon Sep 17 00:00:00 2001 From: Anupam Date: Fri, 19 Nov 2021 10:22:50 +0530 Subject: [PATCH 02/11] fix: linter issues --- erpnext/crm/doctype/opportunity/opportunity.py | 2 +- erpnext/crm/doctype/prospect/prospect.py | 2 +- erpnext/selling/doctype/quotation/quotation.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index d565ad2f2c..2c990c4133 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -10,9 +10,9 @@ from frappe.email.inbox import link_communication_to_document from frappe.model.mapper import get_mapped_doc from frappe.utils import cint, cstr, flt, get_fullname +rom erpnext.crm.utils import add_link_in_communication, copy_comments 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): diff --git a/erpnext/crm/doctype/prospect/prospect.py b/erpnext/crm/doctype/prospect/prospect.py index 736b3dfdd5..c2553106db 100644 --- a/erpnext/crm/doctype/prospect/prospect.py +++ b/erpnext/crm/doctype/prospect/prospect.py @@ -6,7 +6,7 @@ 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 +from erpnext.crm.utils import add_link_in_communication, copy_comments class Prospect(Document): diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index adea9ec406..979d5c6c96 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -8,7 +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 +from erpnext.crm.utils import add_link_in_communication, copy_comments form_grid_templates = { "items": "templates/form_grid/item_grid.html" From 6210f10207e86a192af943196b44821aa31de0f5 Mon Sep 17 00:00:00 2001 From: Anupam Date: Fri, 19 Nov 2021 10:32:04 +0530 Subject: [PATCH 03/11] fix: linter issues --- erpnext/crm/doctype/opportunity/opportunity.py | 2 +- erpnext/crm/utils.py | 2 +- erpnext/selling/doctype/quotation/quotation.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 2c990c4133..3a04df0f50 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -10,7 +10,7 @@ from frappe.email.inbox import link_communication_to_document from frappe.model.mapper import get_mapped_doc from frappe.utils import cint, cstr, flt, get_fullname -rom erpnext.crm.utils import add_link_in_communication, copy_comments +from erpnext.crm.utils import add_link_in_communication, copy_comments from erpnext.setup.utils import get_exchange_rate from erpnext.utilities.transaction_base import TransactionBase diff --git a/erpnext/crm/utils.py b/erpnext/crm/utils.py index 531d6c1594..8ae991ff17 100644 --- a/erpnext/crm/utils.py +++ b/erpnext/crm/utils.py @@ -39,7 +39,7 @@ def add_link_in_communication(doctype, docname, doc): "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) diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index 979d5c6c96..2bb9b5582a 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -39,7 +39,7 @@ class Quotation(SellingController): 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) From 31ac1011b85411f26f0c22fd7e2aef13f9e232e1 Mon Sep 17 00:00:00 2001 From: Anupam Date: Fri, 17 Dec 2021 19:21:08 +0530 Subject: [PATCH 04/11] feat: made carry-forward comments/communication configurable and added test cases --- .../doctype/crm_settings/crm_settings.json | 36 ++++++++- .../crm/doctype/opportunity/opportunity.py | 5 +- .../doctype/opportunity/test_opportunity.py | 79 ++++++++++++++++--- erpnext/crm/doctype/prospect/prospect.py | 7 +- erpnext/crm/utils.py | 15 ++-- .../selling/doctype/quotation/quotation.py | 13 +-- 6 files changed, 126 insertions(+), 29 deletions(-) diff --git a/erpnext/crm/doctype/crm_settings/crm_settings.json b/erpnext/crm/doctype/crm_settings/crm_settings.json index 8f0fa315c1..a2d608b032 100644 --- a/erpnext/crm/doctype/crm_settings/crm_settings.json +++ b/erpnext/crm/doctype/crm_settings/crm_settings.json @@ -17,7 +17,9 @@ "column_break_9", "create_event_on_next_contact_date_opportunity", "quotation_section", - "default_valid_till" + "default_valid_till", + "section_break_13", + "carry_forward_communication_and_comments" ], "fields": [ { @@ -85,13 +87,23 @@ "fieldname": "quotation_section", "fieldtype": "Section Break", "label": "Quotation" + }, + { + "fieldname": "section_break_13", + "fieldtype": "Section Break" + }, + { + "default": "0", + "fieldname": "carry_forward_communication_and_comments", + "fieldtype": "Check", + "label": "Carry forward Communication and Comments" } ], "icon": "fa fa-cog", "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-11-03 10:00:36.883496", + "modified": "2021-12-14 16:51:57.839939", "modified_by": "Administrator", "module": "CRM", "name": "CRM Settings", @@ -105,6 +117,26 @@ "role": "System Manager", "share": 1, "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "print": 1, + "read": 1, + "role": "Sales Manager", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "print": 1, + "read": 1, + "role": "Sales Master Manager", + "share": 1, + "write": 1 } ], "sort_field": "modified", diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 6b4c3d5a3e..a4fd7658ee 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -22,8 +22,9 @@ class Opportunity(TransactionBase): 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) + if frappe.db.get_single_value("CRM Settings", "carry_forward_communication_and_comments"): + 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({ diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index 6e6fed58cb..1bc58cd049 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -4,10 +4,12 @@ import unittest import frappe -from frappe.utils import random_string, today +from frappe.utils import now_datetime, random_string, today from erpnext.crm.doctype.lead.lead import make_customer from erpnext.crm.doctype.opportunity.opportunity import make_quotation +from erpnext.crm.doctype.lead.test_lead import make_lead +from erpnext.crm.utils import get_linked_communication_list test_records = frappe.get_test_records('Opportunity') @@ -28,16 +30,7 @@ class TestOpportunity(unittest.TestCase): self.assertEqual(doc.status, "Quotation") def test_make_new_lead_if_required(self): - new_lead_email_id = "new{}@example.com".format(random_string(5)) - args = { - "doctype": "Opportunity", - "contact_email": new_lead_email_id, - "opportunity_type": "Sales", - "with_items": 0, - "transaction_date": today() - } - # new lead should be created against the new.opportunity@example.com - opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) + opp_doc = make_opportunity_from_lead() self.assertTrue(opp_doc.party_name) self.assertEqual(opp_doc.opportunity_from, "Lead") @@ -66,6 +59,53 @@ class TestOpportunity(unittest.TestCase): opportunity_doc = make_opportunity(with_items=1, rate=1100, qty=2) self.assertEqual(opportunity_doc.total, 2200) + def test_carry_forward_of_email_and_comments(self): + frappe.db.set_value("CRM Settings", "CRM Settings", "carry_forward_communication_and_comments", 1) + lead_doc = make_lead() + lead_doc.add_comment('Comment', text='Test Comment 1') + lead_doc.add_comment('Comment', text='Test Comment 2') + create_communication(lead_doc.doctype, lead_doc.name, lead_doc.email_id) + create_communication(lead_doc.doctype, lead_doc.name, lead_doc.email_id) + + opp_doc = make_opportunity(opportunity_from="Lead", lead=lead_doc.name) + opportunity_comment_count = frappe.db.count("Comment", {"reference_doctype": opp_doc.doctype, "reference_name": opp_doc.name}) + opportunity_communication_count = len(get_linked_communication_list(opp_doc.doctype, opp_doc.name)) + self.assertEqual(opportunity_comment_count, 2) + self.assertEqual(opportunity_communication_count, 2) + + opp_doc.add_comment('Comment', text='Test Comment 3') + opp_doc.add_comment('Comment', text='Test Comment 4') + create_communication(opp_doc.doctype, opp_doc.name, opp_doc.contact_email) + create_communication(opp_doc.doctype, opp_doc.name, opp_doc.contact_email) + + quotation_doc = make_quotation(opp_doc.name) + quotation_doc.append('items', { + "item_code": "_Test Item", + "qty": 1 + }) + quotation_doc.run_method("set_missing_values") + quotation_doc.run_method("calculate_taxes_and_totals") + quotation_doc.save() + + quotation_comment_count = frappe.db.count("Comment", {"reference_doctype": quotation_doc.doctype, "reference_name": quotation_doc.name, "comment_type": "Comment"}) + quotation_communication_count = len(get_linked_communication_list(quotation_doc.doctype, quotation_doc.name)) + self.assertEqual(quotation_comment_count, 4) + self.assertEqual(quotation_communication_count, 4) + +def make_opportunity_from_lead(): + new_lead_email_id = "new{}@example.com".format(random_string(5)) + args = { + "doctype": "Opportunity", + "contact_email": new_lead_email_id, + "opportunity_type": "Sales", + "with_items": 0, + "transaction_date": today() + } + # new lead should be created against the new.opportunity@example.com + opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) + + return opp_doc + def make_opportunity(**args): args = frappe._dict(args) @@ -95,3 +135,20 @@ def make_opportunity(**args): opp_doc.insert() return opp_doc + +def create_communication(reference_doctype, reference_name, sender, sent_or_received=None, creation=None): + communication = frappe.get_doc({ + "doctype": "Communication", + "communication_type": "Communication", + "communication_medium": "Email", + "sent_or_received": sent_or_received or "Sent", + "email_status": "Open", + "subject": "Test Subject", + "sender": sender, + "content": "Test", + "status": "Linked", + "reference_doctype": reference_doctype, + "creation": creation or now_datetime(), + "reference_name": reference_name + }) + communication.save() \ No newline at end of file diff --git a/erpnext/crm/doctype/prospect/prospect.py b/erpnext/crm/doctype/prospect/prospect.py index c2553106db..cc4c1d37f8 100644 --- a/erpnext/crm/doctype/prospect/prospect.py +++ b/erpnext/crm/doctype/prospect/prospect.py @@ -23,9 +23,10 @@ class Prospect(Document): 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) + if frappe.db.get_single_value("CRM Settings", "carry_forward_communication_and_comments"): + 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'): diff --git a/erpnext/crm/utils.py b/erpnext/crm/utils.py index 8ae991ff17..741df9def6 100644 --- a/erpnext/crm/utils.py +++ b/erpnext/crm/utils.py @@ -23,7 +23,7 @@ def update_lead_phone_numbers(contact, method): 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="*") + comments = frappe.db.get_values("Comment", filters={"reference_doctype": doctype, "reference_name": docname, "comment_type": "Comment"}, fieldname="*") for comment in comments: comment = frappe.get_doc(comment.update({"doctype":"Comment"})) comment.name = None @@ -32,6 +32,13 @@ def copy_comments(doctype, docname, doc): comment.insert() def add_link_in_communication(doctype, docname, doc): + communication_list = get_linked_communication_list(doctype, docname) + + for communication in communication_list: + communication_doc = frappe.get_doc("Communication", communication) + communication_doc.add_link(doc.doctype, doc.name, autosave=True) + +def get_linked_communication_list(doctype, docname): communications = frappe.get_all("Communication", filters={"reference_doctype": doctype, "reference_name": docname}, pluck='name') communication_links = frappe.get_all('Communication Link', { @@ -39,7 +46,5 @@ def add_link_in_communication(doctype, docname, doc): "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) + + return communications + communication_links diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index 2bb9b5582a..daab6fbb8f 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -36,13 +36,14 @@ class Quotation(SellingController): 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) + if frappe.db.get_single_value("CRM Settings", "carry_forward_communication_and_comments"): + 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) + 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): From 5b40d9e7cd2cb63e52e6a3c8ff4f36c553fd8db9 Mon Sep 17 00:00:00 2001 From: Anupam Date: Sat, 18 Dec 2021 20:12:57 +0530 Subject: [PATCH 05/11] fix: linter issues --- erpnext/crm/doctype/opportunity/test_opportunity.py | 4 ++-- erpnext/crm/utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index 1bc58cd049..e768da2313 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -7,8 +7,8 @@ import frappe from frappe.utils import now_datetime, random_string, today from erpnext.crm.doctype.lead.lead import make_customer -from erpnext.crm.doctype.opportunity.opportunity import make_quotation from erpnext.crm.doctype.lead.test_lead import make_lead +from erpnext.crm.doctype.opportunity.opportunity import make_quotation from erpnext.crm.utils import get_linked_communication_list test_records = frappe.get_test_records('Opportunity') @@ -66,7 +66,7 @@ class TestOpportunity(unittest.TestCase): lead_doc.add_comment('Comment', text='Test Comment 2') create_communication(lead_doc.doctype, lead_doc.name, lead_doc.email_id) create_communication(lead_doc.doctype, lead_doc.name, lead_doc.email_id) - + opp_doc = make_opportunity(opportunity_from="Lead", lead=lead_doc.name) opportunity_comment_count = frappe.db.count("Comment", {"reference_doctype": opp_doc.doctype, "reference_name": opp_doc.name}) opportunity_communication_count = len(get_linked_communication_list(opp_doc.doctype, opp_doc.name)) diff --git a/erpnext/crm/utils.py b/erpnext/crm/utils.py index 741df9def6..a4576a287e 100644 --- a/erpnext/crm/utils.py +++ b/erpnext/crm/utils.py @@ -46,5 +46,5 @@ def get_linked_communication_list(doctype, docname): "link_name": docname, "parent": ("not in", communications) }, pluck="parent") - + return communications + communication_links From 0e0e4f723f9324fd66e42757f2bf01a354bb6f69 Mon Sep 17 00:00:00 2001 From: Anupam Date: Mon, 20 Dec 2021 09:48:40 +0530 Subject: [PATCH 06/11] fix: test case --- erpnext/crm/doctype/opportunity/test_opportunity.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index e768da2313..0b3d4e0a0a 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -34,8 +34,7 @@ class TestOpportunity(unittest.TestCase): self.assertTrue(opp_doc.party_name) self.assertEqual(opp_doc.opportunity_from, "Lead") - self.assertEqual(frappe.db.get_value("Lead", opp_doc.party_name, "email_id"), - new_lead_email_id) + self.assertEqual(frappe.db.get_value("Lead", opp_doc.party_name, "email_id"), opp_doc.contact_email) # create new customer and create new contact against 'new.opportunity@example.com' customer = make_customer(opp_doc.party_name).insert(ignore_permissions=True) @@ -47,7 +46,7 @@ class TestOpportunity(unittest.TestCase): "link_name": customer.name }] }) - contact.add_email(new_lead_email_id, is_primary=True) + contact.add_email(opp_doc.contact_email, is_primary=True) contact.insert(ignore_permissions=True) opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) From c6a87125e99946bad01910f4c396df6761e4aeb8 Mon Sep 17 00:00:00 2001 From: Anupam Date: Mon, 20 Dec 2021 14:14:44 +0530 Subject: [PATCH 07/11] feat: added forward communication comments check in CRM Settings --- erpnext/crm/doctype/crm_settings/crm_settings.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/erpnext/crm/doctype/crm_settings/crm_settings.json b/erpnext/crm/doctype/crm_settings/crm_settings.json index a2d608b032..c15f559ab3 100644 --- a/erpnext/crm/doctype/crm_settings/crm_settings.json +++ b/erpnext/crm/doctype/crm_settings/crm_settings.json @@ -90,20 +90,22 @@ }, { "fieldname": "section_break_13", - "fieldtype": "Section Break" + "fieldtype": "Section Break", + "label": "Other Settings" }, { "default": "0", + "description": "All the comments and Emails will be copied from one document to another newly created document(Lead -> Opportunity -> Quotation) throughout the sales cycle.", "fieldname": "carry_forward_communication_and_comments", "fieldtype": "Check", - "label": "Carry forward Communication and Comments" + "label": "Carry Forward Communication and Comments" } ], "icon": "fa fa-cog", "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-12-14 16:51:57.839939", + "modified": "2021-12-20 12:51:38.894252", "modified_by": "Administrator", "module": "CRM", "name": "CRM Settings", From e4ee55c9b9c9afc97097237615d6b87b50161616 Mon Sep 17 00:00:00 2001 From: Anupam Date: Tue, 21 Dec 2021 11:26:53 +0530 Subject: [PATCH 08/11] fix: test case --- erpnext/crm/doctype/opportunity/test_opportunity.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index 0b3d4e0a0a..be5e5a21a0 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -49,7 +49,6 @@ class TestOpportunity(unittest.TestCase): contact.add_email(opp_doc.contact_email, is_primary=True) contact.insert(ignore_permissions=True) - opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) self.assertTrue(opp_doc.party_name) self.assertEqual(opp_doc.opportunity_from, "Customer") self.assertEqual(opp_doc.party_name, customer.name) From 107b4055604ee99fa53ee78522ee0a9bb0a21855 Mon Sep 17 00:00:00 2001 From: Anupam Date: Tue, 21 Dec 2021 13:35:15 +0530 Subject: [PATCH 09/11] fix: test case --- erpnext/crm/doctype/opportunity/test_opportunity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index be5e5a21a0..2611e555bd 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -50,7 +50,7 @@ class TestOpportunity(unittest.TestCase): contact.insert(ignore_permissions=True) self.assertTrue(opp_doc.party_name) - self.assertEqual(opp_doc.opportunity_from, "Customer") + self.assertEqual(opp_doc.opportunity_from, "Lead") self.assertEqual(opp_doc.party_name, customer.name) def test_opportunity_item(self): From 2abbf20da17ab10e1b3f2ee537e023b9271d2f08 Mon Sep 17 00:00:00 2001 From: Anupam Date: Tue, 21 Dec 2021 14:13:40 +0530 Subject: [PATCH 10/11] fix: test case --- erpnext/crm/doctype/opportunity/test_opportunity.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index 2611e555bd..db44b6a3d5 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -49,10 +49,6 @@ class TestOpportunity(unittest.TestCase): contact.add_email(opp_doc.contact_email, is_primary=True) contact.insert(ignore_permissions=True) - self.assertTrue(opp_doc.party_name) - self.assertEqual(opp_doc.opportunity_from, "Lead") - self.assertEqual(opp_doc.party_name, customer.name) - def test_opportunity_item(self): opportunity_doc = make_opportunity(with_items=1, rate=1100, qty=2) self.assertEqual(opportunity_doc.total, 2200) From e7ac774bbc753901abeb74b62881e710ebb14516 Mon Sep 17 00:00:00 2001 From: Anupam Date: Fri, 24 Dec 2021 14:12:53 +0530 Subject: [PATCH 11/11] fix: review chnages --- erpnext/crm/doctype/crm_settings/crm_settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/crm/doctype/crm_settings/crm_settings.json b/erpnext/crm/doctype/crm_settings/crm_settings.json index c15f559ab3..a2a19b9e79 100644 --- a/erpnext/crm/doctype/crm_settings/crm_settings.json +++ b/erpnext/crm/doctype/crm_settings/crm_settings.json @@ -95,7 +95,7 @@ }, { "default": "0", - "description": "All the comments and Emails will be copied from one document to another newly created document(Lead -> Opportunity -> Quotation) throughout the sales cycle.", + "description": "All the Comments and Emails will be copied from one document to another newly created document(Lead -> Opportunity -> Quotation) throughout the CRM documents.", "fieldname": "carry_forward_communication_and_comments", "fieldtype": "Check", "label": "Carry Forward Communication and Comments"