From b54459e5883c578cfb66fedfcbe027900e01f9a0 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Mon, 22 Jul 2019 03:23:40 +0530 Subject: [PATCH] dash: added Email Campaign to CRM dashboard --- erpnext/config/crm.py | 5 +++++ erpnext/crm/doctype/email_campaign/email_campaign.py | 8 +++++++- erpnext/hooks.py | 2 +- erpnext/www/lms/macros/__init__.py | 0 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 erpnext/www/lms/macros/__init__.py diff --git a/erpnext/config/crm.py b/erpnext/config/crm.py index e49fc60f63..70784f3d5f 100644 --- a/erpnext/config/crm.py +++ b/erpnext/config/crm.py @@ -141,6 +141,11 @@ def get_data(): "name": "Campaign", "description": _("Sales campaigns."), }, + { + "type": "doctype", + "name": "Email Campaign", + "description": _("Sends Mails to lead or contact based on a Campaign schedule"), + }, { "type": "doctype", "name": "SMS Center", diff --git a/erpnext/crm/doctype/email_campaign/email_campaign.py b/erpnext/crm/doctype/email_campaign/email_campaign.py index 25d54af333..fa4a4ed67f 100644 --- a/erpnext/crm/doctype/email_campaign/email_campaign.py +++ b/erpnext/crm/doctype/email_campaign/email_campaign.py @@ -15,6 +15,7 @@ class EmailCampaign(Document): #checking if email is set for lead. Not checking for contact as email is a mandatory field for contact. if self.email_campaign_for == "Lead": self.validate_lead() + self.validate_email_campaign_already_exists() self.update_status() def validate_dates(self): @@ -40,6 +41,10 @@ class EmailCampaign(Document): if not lead_email_id: frappe.throw(_("Please set an email id for lead communication")) + def validate_email_campaign_already_exists(self): + if frappe.db.get_value("Email Campaign", {"campaign_name": self.campaign_name, "recipient": self.recipient, "status": "Active"}): + frappe.throw(_("The Campaign '{0}' already exists for the {1} '{2}'").format(self.campaign_name, self.email_campaign_for, self.recipient)) + def update_status(self): start_date = getdate(self.start_date) end_date = getdate(self.end_date) @@ -52,7 +57,7 @@ class EmailCampaign(Document): self.status = "Completed" #called through hooks to send campaign mails to leads -def send_email_to_leads(): +def send_email_to_leads_or_contacts(): email_campaigns = frappe.get_all("Email Campaign", filters = { 'status': ('not in', ['Unsubscribed', 'Completed', 'Scheduled']) }) for camp in email_campaigns: email_campaign = frappe.get_doc("Email Campaign", camp.name) @@ -81,6 +86,7 @@ def send_mail(entry, email_campaign): send_email = True, email_template = email_template.name ) + return comm #called from hooks on doc_event Email Unsubscribe def unsubscribe_recipient(unsubscribe, method): diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 48d133fdff..47d1a68efc 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -275,7 +275,7 @@ scheduler_events = { "erpnext.projects.doctype.project.project.send_project_status_email_to_users", "erpnext.quality_management.doctype.quality_review.quality_review.review", "erpnext.support.doctype.service_level_agreement.service_level_agreement.check_agreement_status", - "erpnext.crm.doctype.email_campaign.email_campaign.send_email_to_leads", + "erpnext.crm.doctype.email_campaign.email_campaign.send_email_to_leads_or_contacts", "erpnext.crm.doctype.email_campaign.email_campaign.set_email_campaign_status" ], "daily_long": [ diff --git a/erpnext/www/lms/macros/__init__.py b/erpnext/www/lms/macros/__init__.py new file mode 100644 index 0000000000..e69de29bb2