Skip to content

Commit

Permalink
Merge pull request #30947 from frappe/mergify/bp/version-13-hotfix/pr…
Browse files Browse the repository at this point in the history
…-30938

fix: allow to use formatting for the field to_discuss in opportunity (backport #30938)
  • Loading branch information
rohitwaghchaure committed May 11, 2022
2 parents b008efb + 87fd933 commit 60964a4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
14 changes: 7 additions & 7 deletions erpnext/crm/doctype/opportunity/opportunity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from frappe import _
from frappe.email.inbox import link_communication_to_document
from frappe.model.mapper import get_mapped_doc
from frappe.utils import cint, cstr, get_fullname
from frappe.utils import cint, get_fullname

from erpnext.accounts.party import get_party_account_currency
from erpnext.setup.utils import get_exchange_rate
Expand Down Expand Up @@ -193,20 +193,20 @@ def add_calendar_event(self, opts=None, force=False):

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)
opts.description += f" To Discuss : {frappe.render_template(self.to_discuss, {'doc': self})}"

super(Opportunity, self).add_calendar_event(opts, force)

Expand Down
18 changes: 17 additions & 1 deletion erpnext/crm/doctype/opportunity/test_opportunity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest

import frappe
from frappe.utils import random_string, today
from frappe.utils import add_days, now_datetime, random_string, today

from erpnext.crm.doctype.lead.lead import make_customer
from erpnext.crm.doctype.opportunity.opportunity import make_quotation
Expand Down Expand Up @@ -58,6 +58,22 @@ def test_make_new_lead_if_required(self):
self.assertEqual(opp_doc.opportunity_from, "Customer")
self.assertEqual(opp_doc.party_name, customer.name)

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(**args):
args = frappe._dict(args)
Expand Down

0 comments on commit 60964a4

Please sign in to comment.