feat(CRM): Email Group Option In Email Campaign (#22731)
* new parent updating logic, made requested changes
* feat: adding Email Group option in Email Campaign
* fix: inv commas
diff --git a/erpnext/crm/doctype/email_campaign/email_campaign.json b/erpnext/crm/doctype/email_campaign/email_campaign.json
index 736a9d6..0340364 100644
--- a/erpnext/crm/doctype/email_campaign/email_campaign.json
+++ b/erpnext/crm/doctype/email_campaign/email_campaign.json
@@ -1,4 +1,5 @@
{
+ "actions": [],
"autoname": "format:MAIL-CAMP-{YYYY}-{#####}",
"creation": "2019-06-30 16:05:30.015615",
"doctype": "DocType",
@@ -52,7 +53,7 @@
"fieldtype": "Select",
"in_list_view": 1,
"label": "Email Campaign For ",
- "options": "\nLead\nContact",
+ "options": "\nLead\nContact\nEmail Group",
"reqd": 1
},
{
@@ -70,7 +71,8 @@
"options": "User"
}
],
- "modified": "2019-11-11 17:18:47.342839",
+ "links": [],
+ "modified": "2020-07-15 12:43:25.548682",
"modified_by": "Administrator",
"module": "CRM",
"name": "Email Campaign",
diff --git a/erpnext/crm/doctype/email_campaign/email_campaign.py b/erpnext/crm/doctype/email_campaign/email_campaign.py
index 8f60ecf..71c93e8 100644
--- a/erpnext/crm/doctype/email_campaign/email_campaign.py
+++ b/erpnext/crm/doctype/email_campaign/email_campaign.py
@@ -70,10 +70,15 @@
send_mail(entry, email_campaign)
def send_mail(entry, email_campaign):
- recipient = frappe.db.get_value(email_campaign.email_campaign_for, email_campaign.get("recipient"), 'email_id')
+ recipient_list = []
+ if email_campaign.email_campaign_for == "Email Group":
+ for member in frappe.db.get_list("Email Group Member", filters={"email_group": email_campaign.get("recipient")}, fields=["email"]):
+ recipient_list.append(member['email'])
+ else:
+ recipient_list.append(frappe.db.get_value(email_campaign.email_campaign_for, email_campaign.get("recipient"), "email_id"))
email_template = frappe.get_doc("Email Template", entry.get("email_template"))
- sender = frappe.db.get_value("User", email_campaign.get("sender"), 'email')
+ sender = frappe.db.get_value("User", email_campaign.get("sender"), "email")
context = {"doc": frappe.get_doc(email_campaign.email_campaign_for, email_campaign.recipient)}
# send mail and link communication to document
comm = make(
@@ -82,7 +87,7 @@
subject = frappe.render_template(email_template.get("subject"), context),
content = frappe.render_template(email_template.get("response"), context),
sender = sender,
- recipients = recipient,
+ recipients = recipient_list,
communication_medium = "Email",
sent_or_received = "Sent",
send_email = True,