From e126d4e5924a91f6f212cc0ac0145265bef0415e Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 9 May 2022 14:58:37 +0530 Subject: [PATCH 1/3] fix: allow to use formatting for the field to_discuss in opportunity (cherry picked from commit 3f41cb762da0141b0118a51f1b1b56928f403dd1) # Conflicts: # erpnext/crm/doctype/opportunity/opportunity.py # erpnext/crm/doctype/opportunity/test_opportunity.py --- .../crm/doctype/opportunity/opportunity.py | 24 ++++++ .../doctype/opportunity/test_opportunity.py | 86 +++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index fc2053439248..c78aaffdfc44 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -8,7 +8,12 @@ from frappe import _ from frappe.email.inbox import link_communication_to_document from frappe.model.mapper import get_mapped_doc +<<<<<<< HEAD from frappe.utils import cint, cstr, get_fullname +======= +from frappe.query_builder import DocType +from frappe.utils import cint, flt, get_fullname +>>>>>>> 3f41cb762d (fix: allow to use formatting for the field to_discuss in opportunity) from erpnext.accounts.party import get_party_account_currency from erpnext.setup.utils import get_exchange_rate @@ -191,6 +196,7 @@ def add_calendar_event(self, opts=None, force=False): opts.description = "" opts.contact_date = self.contact_date +<<<<<<< HEAD if self.party_name and self.opportunity_from == "Customer": if self.contact_person: opts.description = "Contact " + cstr(self.contact_person) @@ -207,6 +213,24 @@ def add_calendar_event(self, opts=None, force=False): if self.to_discuss: opts.description += " To Discuss : " + cstr(self.to_discuss) +======= + if self.party_name and self.opportunity_from == "Customer": + if self.contact_person: + opts.description = f"Contact {self.contact_person}" + else: + opts.description = f"Contact customer {self.party_name}" + elif self.party_name and self.opportunity_from == "Lead": + if self.contact_display: + opts.description = f"Contact {self.contact_display}" + else: + opts.description = f"Contact lead {self.party_name}" + + opts.subject = opts.description + opts.description += f". By : {self.contact_by}" + + if self.to_discuss: + opts.description += f" To Discuss : {frappe.render_template(self.to_discuss, {'doc': self})}" +>>>>>>> 3f41cb762d (fix: allow to use formatting for the field to_discuss in opportunity) super(Opportunity, self).add_calendar_event(opts, force) diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index cfe267c60c6f..8c70424d35ad 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -4,7 +4,11 @@ import unittest import frappe +<<<<<<< HEAD from frappe.utils import random_string, today +======= +from frappe.utils import add_days, now_datetime, random_string, today +>>>>>>> 3f41cb762d (fix: allow to use formatting for the field to_discuss in opportunity) from erpnext.crm.doctype.lead.lead import make_customer from erpnext.crm.doctype.opportunity.opportunity import make_quotation @@ -53,10 +57,92 @@ def test_make_new_lead_if_required(self): contact.add_email(new_lead_email_id, is_primary=True) contact.insert(ignore_permissions=True) +<<<<<<< HEAD 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) +======= + def test_opportunity_item(self): + 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 test_render_template_for_to_discuss(self): + doc = make_opportunity(with_items=0, opportunity_from="Lead") + doc.contact_by = "test@example.com" + doc.contact_date = add_days(today(), days=2) + doc.to_discuss = "{{ doc.name }} test data" + doc.save() + + event = frappe.get_all( + "Event Participants", + fields=["parent"], + filters={"reference_doctype": doc.doctype, "reference_docname": doc.name}, + ) + + event_description = frappe.db.get_value("Event", event[0].parent, "description") + self.assertTrue(doc.name in event_description) + + +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 +>>>>>>> 3f41cb762d (fix: allow to use formatting for the field to_discuss in opportunity) def make_opportunity(**args): From fb62bbf61af1e3cb0652382051bfcd24e6ad79b7 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Wed, 11 May 2022 16:05:19 +0530 Subject: [PATCH 2/3] fix: conflicts --- .../crm/doctype/opportunity/opportunity.py | 38 ++++--------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index c78aaffdfc44..676da31a63ac 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -8,12 +8,7 @@ from frappe import _ from frappe.email.inbox import link_communication_to_document from frappe.model.mapper import get_mapped_doc -<<<<<<< HEAD -from frappe.utils import cint, cstr, get_fullname -======= -from frappe.query_builder import DocType -from frappe.utils import cint, flt, get_fullname ->>>>>>> 3f41cb762d (fix: allow to use formatting for the field to_discuss in opportunity) +from frappe.utils import cint, get_fullname from erpnext.accounts.party import get_party_account_currency from erpnext.setup.utils import get_exchange_rate @@ -196,41 +191,22 @@ def add_calendar_event(self, opts=None, force=False): opts.description = "" opts.contact_date = self.contact_date -<<<<<<< HEAD if self.party_name and self.opportunity_from == "Customer": if self.contact_person: - opts.description = "Contact " + cstr(self.contact_person) + opts.description = f"Contact {self.contact_person}" else: - opts.description = "Contact customer " + cstr(self.party_name) + opts.description = f"Contact customer {self.party_name}" elif self.party_name and self.opportunity_from == "Lead": if self.contact_display: - opts.description = "Contact " + cstr(self.contact_display) + opts.description = f"Contact {self.contact_display}" else: - opts.description = "Contact lead " + cstr(self.party_name) + opts.description = f"Contact lead {self.party_name}" opts.subject = opts.description - opts.description += ". By : " + cstr(self.contact_by) + opts.description += f". By : {self.contact_by}" if self.to_discuss: - opts.description += " To Discuss : " + cstr(self.to_discuss) -======= - if self.party_name and self.opportunity_from == "Customer": - if self.contact_person: - opts.description = f"Contact {self.contact_person}" - else: - opts.description = f"Contact customer {self.party_name}" - elif self.party_name and self.opportunity_from == "Lead": - if self.contact_display: - opts.description = f"Contact {self.contact_display}" - else: - opts.description = f"Contact lead {self.party_name}" - - opts.subject = opts.description - opts.description += f". By : {self.contact_by}" - - if self.to_discuss: - opts.description += f" To Discuss : {frappe.render_template(self.to_discuss, {'doc': self})}" ->>>>>>> 3f41cb762d (fix: allow to use formatting for the field to_discuss in opportunity) + opts.description += f" To Discuss : {frappe.render_template(self.to_discuss, {'doc': self})}" super(Opportunity, self).add_calendar_event(opts, force) From 87fd93370abf55f822e41cce72a8060ee4632247 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Wed, 11 May 2022 16:07:24 +0530 Subject: [PATCH 3/3] fix: conflicts --- .../doctype/opportunity/test_opportunity.py | 70 ------------------- 1 file changed, 70 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index 8c70424d35ad..cd4ede2ab9c1 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -4,11 +4,7 @@ import unittest import frappe -<<<<<<< HEAD -from frappe.utils import random_string, today -======= from frappe.utils import add_days, now_datetime, random_string, today ->>>>>>> 3f41cb762d (fix: allow to use formatting for the field to_discuss in opportunity) from erpnext.crm.doctype.lead.lead import make_customer from erpnext.crm.doctype.opportunity.opportunity import make_quotation @@ -57,60 +53,10 @@ def test_make_new_lead_if_required(self): contact.add_email(new_lead_email_id, is_primary=True) contact.insert(ignore_permissions=True) -<<<<<<< HEAD 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) -======= - def test_opportunity_item(self): - 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 test_render_template_for_to_discuss(self): doc = make_opportunity(with_items=0, opportunity_from="Lead") @@ -129,22 +75,6 @@ def test_render_template_for_to_discuss(self): self.assertTrue(doc.name in event_description) -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 ->>>>>>> 3f41cb762d (fix: allow to use formatting for the field to_discuss in opportunity) - - def make_opportunity(**args): args = frappe._dict(args)