From cb45836cda5df030571c769761f1a9afa9f6a101 Mon Sep 17 00:00:00 2001 From: Abhishek Balam Date: Thu, 23 Jul 2020 19:07:11 +0530 Subject: [PATCH] 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 --- .../crm/doctype/email_campaign/email_campaign.json | 6 ++++-- erpnext/crm/doctype/email_campaign/email_campaign.py | 11 ++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/erpnext/crm/doctype/email_campaign/email_campaign.json b/erpnext/crm/doctype/email_campaign/email_campaign.json index 736a9d6173..0340364bd5 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 8f60ecf621..71c93e8d39 100644 --- a/erpnext/crm/doctype/email_campaign/email_campaign.py +++ b/erpnext/crm/doctype/email_campaign/email_campaign.py @@ -70,10 +70,15 @@ def send_email_to_leads_or_contacts(): 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 @@ def send_mail(entry, email_campaign): 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,