Added override for email campaign sending to send emails at 08:15AM instead of midnight

This commit is contained in:
Jeremy Rangel
2025-06-04 18:09:56 -07:00
parent c51e7a8086
commit 2dfac129fa
20 changed files with 204 additions and 0 deletions

View File

@ -0,0 +1 @@
__version__ = "0.0.1"

View File

@ -0,0 +1,26 @@
import frappe
def after_install():
stop_erpnext_scheduled_send_email_job()
def stop_erpnext_scheduled_send_email_job():
# Get list of Scheduled Job Type docs with that method
job_docs = frappe.get_all(
"Scheduled Job Type",
filters={"method": "erpnext.crm.doctype.email_campaign.email_campaign.send_email_to_leads_or_contacts"},
limit_page_length=1
)
if not job_docs:
frappe.msgprint("Scheduled Job Type not found.")
return
job_name = job_docs[0].name
job_doc = frappe.get_doc("Scheduled Job Type", job_name)
# Set stopped = 1
job_doc.stopped = 1
job_doc.save(ignore_permissions=True)
frappe.db.commit()
frappe.msgprint(f"Scheduled Job Type '{job_doc.method}' stopped successfully.")

View File

@ -0,0 +1 @@
__version__ = "0.0.1"

View File

@ -0,0 +1,31 @@
import frappe
from frappe.utils import today
@frappe.whitelist()
def add_lead_to_campaign(lead_name, campaign_name, start_date=None):
if not frappe.db.exists("Lead", lead_name):
frappe.throw("Lead does not exist")
# Check if there's already a scheduled/in-progress campaign for this Lead with same name
existing = frappe.db.exists("Email Campaign", {
"recipient": lead_name,
"campaign_name": campaign_name,
"email_campaign_for": "Lead",
"status": ["in", ["Scheduled", "In Progress"]]
})
if existing:
frappe.throw("This Lead is already part of an Email Campaign with this name.")
doc = frappe.new_doc("Email Campaign")
doc.update({
"campaign_name": campaign_name,
"email_campaign_for": "Lead",
"recipient": lead_name,
"start_date": start_date or today(),
"sender": frappe.session.user # or replace with a specific default sender
})
doc.insert(ignore_permissions=True)
frappe.db.commit()
return {"status": "success", "message": "Email Campaign created"}

View File

@ -0,0 +1 @@
__version__ = "0.0.1"

View File

@ -0,0 +1,4 @@
from erpnext.crm.doctype.email_campaign.email_campaign import send_email_to_leads_or_contacts as erpnext_send_email
def send_email_to_leads_or_contacts():
erpnext_send_email()

View File

@ -0,0 +1,26 @@
import frappe
def before_uninstall():
start_erpnext_scheduled_send_email_job()
def start_erpnext_scheduled_send_email_job():
# Get list of Scheduled Job Type docs with that method
job_docs = frappe.get_all(
"Scheduled Job Type",
filters={"method": "erpnext.crm.doctype.email_campaign.email_campaign.send_email_to_leads_or_contacts"},
limit_page_length=1
)
if not job_docs:
frappe.msgprint("Scheduled Job Type not found.")
return
job_name = job_docs[0].name
job_doc = frappe.get_doc("Scheduled Job Type", job_name)
# Set stopped = 1
job_doc.stopped = 0
job_doc.save(ignore_permissions=True)
frappe.db.commit()
frappe.msgprint(f"Scheduled Job Type '{job_doc.method}' stopped successfully.")