Skip to content

Commit 00bb07a

Browse files
Shllokkkmergify[bot]
authored andcommitted
fix(email_campaign): prevent unsubscribing entire campaign when email group member unsubscribes
(cherry picked from commit 56f597f)
1 parent 3d79dce commit 00bb07a

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

erpnext/crm/doctype/email_campaign/email_campaign.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,22 @@ def send_mail(entry, email_campaign):
204204

205205
# called from hooks on doc_event Email Unsubscribe
206206
def unsubscribe_recipient(unsubscribe, method):
207-
if unsubscribe.reference_doctype == "Email Campaign":
208-
frappe.db.set_value("Email Campaign", unsubscribe.reference_name, "status", "Unsubscribed")
207+
if unsubscribe.reference_doctype != "Email Campaign":
208+
return
209+
210+
email_campaign = frappe.get_doc("Email Campaign", unsubscribe.reference_name)
211+
212+
if email_campaign.email_campaign_for == "Email Group":
213+
if unsubscribe.email:
214+
frappe.db.set_value(
215+
"Email Group Member",
216+
{"email_group": email_campaign.recipient, "email": unsubscribe.email},
217+
"unsubscribed",
218+
1,
219+
)
220+
else:
221+
# For Lead or Contact
222+
frappe.db.set_value("Email Campaign", email_campaign.name, "status", "Unsubscribed")
209223

210224

211225
# called through hooks to update email campaign status daily

0 commit comments

Comments
 (0)