mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-09 00:01:18 +00:00
fix: implement get_notification_email hook on Opportunity, Prospect and Customer (#54789)
This commit is contained in:
@@ -148,6 +148,15 @@ class TestLead(ERPNextTestSuite):
|
||||
self.assertEqual(event.event_participants[1].reference_doctype, "Prospect")
|
||||
self.assertEqual(event.event_participants[1].reference_docname, prospect)
|
||||
|
||||
def test_get_notification_email(self):
|
||||
admin_email = frappe.db.get_value("User", "Administrator", "email")
|
||||
lead = frappe.new_doc("Lead")
|
||||
lead.lead_owner = "Administrator"
|
||||
self.assertEqual(lead.get_notification_email(), admin_email)
|
||||
|
||||
lead.lead_owner = None
|
||||
self.assertIsNone(lead.get_notification_email())
|
||||
|
||||
|
||||
def create_event(subject, starts_on, reference_type, reference_name):
|
||||
event = frappe.new_doc("Event")
|
||||
|
||||
@@ -363,6 +363,13 @@ class Opportunity(TransactionBase, CRMNote):
|
||||
if not d.get(key):
|
||||
d.set(key, item.get(key))
|
||||
|
||||
def get_notification_email(self):
|
||||
"""Hook to return the target email address for notifications."""
|
||||
if self.opportunity_owner:
|
||||
return frappe.db.get_value("User", self.opportunity_owner, "email")
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_item_details(item_code: str):
|
||||
|
||||
@@ -91,6 +91,15 @@ class TestOpportunity(ERPNextTestSuite):
|
||||
create_communication(opp_doc.doctype, opp_doc.name, opp_doc.contact_email)
|
||||
create_communication(opp_doc.doctype, opp_doc.name, opp_doc.contact_email)
|
||||
|
||||
def test_get_notification_email(self):
|
||||
admin_email = frappe.db.get_value("User", "Administrator", "email")
|
||||
opp = frappe.new_doc("Opportunity")
|
||||
opp.opportunity_owner = "Administrator"
|
||||
self.assertEqual(opp.get_notification_email(), admin_email)
|
||||
|
||||
opp.opportunity_owner = None
|
||||
self.assertIsNone(opp.get_notification_email())
|
||||
|
||||
|
||||
def make_opportunity_from_lead(company):
|
||||
new_lead_email_id = f"new{random_string(5)}@example.com"
|
||||
|
||||
@@ -86,6 +86,13 @@ class Prospect(CRMNote):
|
||||
linked_doc.append("links", {"link_doctype": self.doctype, "link_name": self.name})
|
||||
linked_doc.save(ignore_permissions=True)
|
||||
|
||||
def get_notification_email(self):
|
||||
"""Hook to return the target email address for notifications."""
|
||||
if self.prospect_owner:
|
||||
return frappe.db.get_value("User", self.prospect_owner, "email")
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_customer(source_name: str, target_doc: str | Document | None = None):
|
||||
|
||||
@@ -51,6 +51,15 @@ class TestProspect(ERPNextTestSuite):
|
||||
customer.company = "_Test Company"
|
||||
customer.insert()
|
||||
|
||||
def test_get_notification_email(self):
|
||||
admin_email = frappe.db.get_value("User", "Administrator", "email")
|
||||
prospect = frappe.new_doc("Prospect")
|
||||
prospect.prospect_owner = "Administrator"
|
||||
self.assertEqual(prospect.get_notification_email(), admin_email)
|
||||
|
||||
prospect.prospect_owner = None
|
||||
self.assertIsNone(prospect.get_notification_email())
|
||||
|
||||
|
||||
def make_prospect(**args):
|
||||
args = frappe._dict(args)
|
||||
|
||||
@@ -442,6 +442,13 @@ class Customer(TransactionBase):
|
||||
)
|
||||
)
|
||||
|
||||
def get_notification_email(self):
|
||||
"""Hook to return the target email address for notifications."""
|
||||
if self.account_manager:
|
||||
return frappe.db.get_value("User", self.account_manager, "email")
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_quotation(source_name: str, target_doc: str | Document | None = None):
|
||||
|
||||
@@ -350,6 +350,15 @@ class TestCustomer(ERPNextTestSuite):
|
||||
self.assertEqual(middle, "Michael")
|
||||
self.assertEqual(last, "Doe")
|
||||
|
||||
def test_get_notification_email(self):
|
||||
admin_email = frappe.db.get_value("User", "Administrator", "email")
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.account_manager = "Administrator"
|
||||
self.assertEqual(customer.get_notification_email(), admin_email)
|
||||
|
||||
customer.account_manager = None
|
||||
self.assertIsNone(customer.get_notification_email())
|
||||
|
||||
|
||||
def get_customer_dict(customer_name):
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user