mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 05:39:12 +00:00
auto email and new communication linked to email campaign setup
This commit is contained in:
@@ -13,7 +13,8 @@
|
|||||||
"status",
|
"status",
|
||||||
"email_schedule_section",
|
"email_schedule_section",
|
||||||
"email_schedule",
|
"email_schedule",
|
||||||
"naming_series"
|
"naming_series",
|
||||||
|
"amended_from"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -42,7 +43,7 @@
|
|||||||
"fieldname": "status",
|
"fieldname": "status",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"label": "Status",
|
"label": "Status",
|
||||||
"options": "\nStarted\nIn Progress\nCompleted"
|
"options": "\nDraft\nSubmitted\nStarted\nIn Progress\nCompleted"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "column_break_4",
|
"fieldname": "column_break_4",
|
||||||
@@ -72,9 +73,19 @@
|
|||||||
"label": "Naming Series",
|
"label": "Naming Series",
|
||||||
"options": "MAIL-CAMP-.YYYY.-",
|
"options": "MAIL-CAMP-.YYYY.-",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "amended_from",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Amended From",
|
||||||
|
"no_copy": 1,
|
||||||
|
"options": "Email Campaign",
|
||||||
|
"print_hide": 1,
|
||||||
|
"read_only": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2019-06-30 16:23:00.696185",
|
"is_submittable": 1,
|
||||||
|
"modified": "2019-06-30 23:00:24.765312",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "CRM",
|
"module": "CRM",
|
||||||
"name": "Email Campaign",
|
"name": "Email Campaign",
|
||||||
|
|||||||
@@ -5,12 +5,14 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import getdate, add_days
|
from frappe.utils import getdate, add_days, nowdate
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.email.inbox import link_communication_to_document
|
||||||
|
|
||||||
class EmailCampaign(Document):
|
class EmailCampaign(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_dates()
|
self.validate_dates()
|
||||||
|
self.validate_lead()
|
||||||
|
|
||||||
def validate_dates(self):
|
def validate_dates(self):
|
||||||
campaign = frappe.get_doc("Campaign", self.campaign_name)
|
campaign = frappe.get_doc("Campaign", self.campaign_name)
|
||||||
@@ -25,4 +27,40 @@ class EmailCampaign(Document):
|
|||||||
no_of_days += entry.send_after_days
|
no_of_days += entry.send_after_days
|
||||||
email_schedule_end_date = add_days(getdate(self.start_date), no_of_days)
|
email_schedule_end_date = add_days(getdate(self.start_date), no_of_days)
|
||||||
if campaign.to_date and getdate(email_schedule_end_date) > getdate(campaign.to_date):
|
if campaign.to_date and getdate(email_schedule_end_date) > getdate(campaign.to_date):
|
||||||
frappe.throw(_("Email Schedule cannot extend Campaign End Date"))
|
frappe.throw(_("Email Schedule cannot extend Campaign End Date"))
|
||||||
|
|
||||||
|
def validate_lead(self):
|
||||||
|
lead = frappe.get_doc("Lead", self.lead)
|
||||||
|
if not lead.get("email_id"):
|
||||||
|
frappe.throw(_("Please set email id for lead communication"))
|
||||||
|
|
||||||
|
def send(self):
|
||||||
|
lead = frappe.get_doc("Lead", self.get("lead"))
|
||||||
|
email_schedule = frappe.get_doc("Campaign Email Schedule", self.get("email_schedule"))
|
||||||
|
email_template = frappe.get_doc("Email Template", email_schedule.name)
|
||||||
|
frappe.sendmail(
|
||||||
|
recipients = lead.get("email_id"),
|
||||||
|
sender = lead.get("lead_owner"),
|
||||||
|
subject = email_template.get("subject"),
|
||||||
|
message = email_template.get("response"),
|
||||||
|
reference_doctype = self.doctype,
|
||||||
|
reference_name = self.name
|
||||||
|
)
|
||||||
|
|
||||||
|
def on_submit(self):
|
||||||
|
"""Create a new communication linked to the campaign if not created"""
|
||||||
|
if not frappe.db.sql("select subject from tabCommunication where reference_name = %s", self.name):
|
||||||
|
doc = frappe.new_doc("Communication")
|
||||||
|
doc.subject = "Email Campaign Communication: " + self.name
|
||||||
|
link_communication_to_document(doc, "Email Campaign", self.name, ignore_communication_links = False)
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def send_email_to_leads():
|
||||||
|
email_campaigns = frappe.get_all("Email Campaign", filters = { 'start_date': ("<=", nowdate()) })
|
||||||
|
for campaign in email_campaigns:
|
||||||
|
email_campaign = frappe.get_doc("Email Campaign", campaign.name)
|
||||||
|
for entry in email_campaign.get("email_schedule"):
|
||||||
|
scheduled_date = add_days(email_campaign.get('start_date'), entry.get('send_after_days'))
|
||||||
|
if(scheduled_date == nowdate()):
|
||||||
|
email_campaign.send()
|
||||||
|
# send_email_to_leads()
|
||||||
|
|||||||
@@ -266,6 +266,7 @@ scheduler_events = {
|
|||||||
"erpnext.projects.doctype.project.project.send_project_status_email_to_users",
|
"erpnext.projects.doctype.project.project.send_project_status_email_to_users",
|
||||||
"erpnext.quality_management.doctype.quality_review.quality_review.review",
|
"erpnext.quality_management.doctype.quality_review.quality_review.review",
|
||||||
"erpnext.support.doctype.service_level_agreement.service_level_agreement.check_agreement_status",
|
"erpnext.support.doctype.service_level_agreement.service_level_agreement.check_agreement_status",
|
||||||
|
"erpnext.crm.doctype.email_campaign.email_campaign.send_email_to_leads"
|
||||||
],
|
],
|
||||||
"daily_long": [
|
"daily_long": [
|
||||||
"erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool.update_latest_price_in_all_boms"
|
"erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool.update_latest_price_in_all_boms"
|
||||||
|
|||||||
Reference in New Issue
Block a user