setting end date in email campaign
diff --git a/erpnext/crm/doctype/email_campaign/email_campaign.py b/erpnext/crm/doctype/email_campaign/email_campaign.py
index 00a4bd1..8f60ecf 100644
--- a/erpnext/crm/doctype/email_campaign/email_campaign.py
+++ b/erpnext/crm/doctype/email_campaign/email_campaign.py
@@ -27,7 +27,7 @@
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 9ef0b8d..d17503b 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -667,3 +667,4 @@
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 0000000..e69de29
--- /dev/null
+++ b/erpnext/patches/v13_0/__init__.py
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 0000000..db71a73
--- /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