From 39911b40f0df220121ac4bd3289b2b156cb4aa2f Mon Sep 17 00:00:00 2001 From: Anupam K Date: Wed, 22 Apr 2020 18:37:15 +0530 Subject: [PATCH] setting end date in email campaign --- .../doctype/email_campaign/email_campaign.py | 2 +- erpnext/patches.txt | 1 + erpnext/patches/v13_0/__init__.py | 0 ...e_end_date_and_status_in_email_campaign.py | 24 +++++++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 erpnext/patches/v13_0/__init__.py create mode 100644 erpnext/patches/v13_0/update_end_date_and_status_in_email_campaign.py diff --git a/erpnext/crm/doctype/email_campaign/email_campaign.py b/erpnext/crm/doctype/email_campaign/email_campaign.py index 00a4bd1a32..8f60ecf621 100644 --- a/erpnext/crm/doctype/email_campaign/email_campaign.py +++ b/erpnext/crm/doctype/email_campaign/email_campaign.py @@ -27,7 +27,7 @@ class EmailCampaign(Document): for entry in campaign.get("campaign_schedules"): send_after_days.append(entry.send_after_days) try: - end_date = add_days(getdate(self.start_date), max(send_after_days)) + self.end_date = add_days(getdate(self.start_date), max(send_after_days)) except ValueError: frappe.throw(_("Please set up the Campaign Schedule in the Campaign {0}").format(self.campaign_name)) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 9ef0b8d510..d17503be9d 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -667,3 +667,4 @@ erpnext.patches.v12_0.update_healthcare_refactored_changes erpnext.patches.v12_0.set_total_batch_quantity erpnext.patches.v12_0.rename_mws_settings_fields erpnext.patches.v12_0.set_updated_purpose_in_pick_list +erpnext.patches.v13_0.update_end_date_and_status_in_email_campaign \ No newline at end of file diff --git a/erpnext/patches/v13_0/__init__.py b/erpnext/patches/v13_0/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/patches/v13_0/update_end_date_and_status_in_email_campaign.py b/erpnext/patches/v13_0/update_end_date_and_status_in_email_campaign.py new file mode 100644 index 0000000000..db71a735de --- /dev/null +++ b/erpnext/patches/v13_0/update_end_date_and_status_in_email_campaign.py @@ -0,0 +1,24 @@ +from __future__ import unicode_literals +import frappe +from frappe.utils import add_days, getdate, today + +def execute(): + if frappe.db.exists('DocType', 'Email Campaign'): + email_campaign = frappe.get_all('Email Campaign') + for campaign in email_campaign: + doc = frappe.get_doc("Email Campaign",campaign["name"]) + send_after_days = [] + + camp = frappe.get_doc("Campaign", doc.campaign_name) + for entry in camp.get("campaign_schedules"): + send_after_days.append(entry.send_after_days) + if send_after_days: + end_date = add_days(getdate(doc.start_date), max(send_after_days)) + doc.db_set("end_date", end_date) + today_date = getdate(today()) + if doc.start_date > today_date: + doc.db_set("status", "Scheduled") + elif end_date >= today_date: + doc.db_set("status", "In Progress") + elif end_date < today_date: + doc.db_set("status", "Completed") \ No newline at end of file