fix: set welcome_email to None if template not found

fixes UnboundLocalError: welcome_email referenced before assignment

Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
This commit is contained in:
Chinmay D. Pai 2020-04-10 15:42:58 +05:30
parent 5d92e7cf9f
commit 9df69d214c
No known key found for this signature in database
GPG key ID: 75507BE256F40CED

View file

@ -68,8 +68,7 @@ def add_subscribers(name, email_list):
email_list = email_list.replace(",", "\n").split("\n")
template = frappe.db.get_value('Email Group', name, 'welcome_email_template')
if template:
welcome_email = frappe.get_doc("Email Template", template)
welcome_email = frappe.get_doc("Email Template", template) if template else None
count = 0
for email in email_list:
@ -108,4 +107,4 @@ def send_welcome_email(welcome_email, email, email_group):
)
message = frappe.render_template(welcome_email.response, args)
frappe.sendmail(email, subject=welcome_email.subject, message=message)
frappe.sendmail(email, subject=welcome_email.subject, message=message)