feat: certification email
This commit is contained in:
@@ -6,12 +6,41 @@ from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import add_years, nowdate
|
||||
from lms.lms.utils import is_certified
|
||||
from frappe.email.doctype.email_template.email_template import get_email_template
|
||||
|
||||
|
||||
class LMSCertificate(Document):
|
||||
def validate(self):
|
||||
self.validate_duplicate_certificate()
|
||||
|
||||
def after_insert(self):
|
||||
self.send_mail()
|
||||
|
||||
def send_mail(self):
|
||||
subject = _("Congratulations on getting certified!")
|
||||
template = "certification"
|
||||
custom_template = frappe.db.get_single_value("LMS Settings", "certification_template")
|
||||
|
||||
args = {
|
||||
"student_name": self.member_name,
|
||||
"course_name": self.course,
|
||||
"course_title": frappe.db.get_value("LMS Course", self.course, "title"),
|
||||
"certificate_name": self.name,
|
||||
}
|
||||
|
||||
if custom_template:
|
||||
email_template = get_email_template(custom_template, args)
|
||||
subject = email_template.get("subject")
|
||||
content = email_template.get("message")
|
||||
frappe.sendmail(
|
||||
recipients=self.member,
|
||||
subject=subject,
|
||||
template=template if not custom_template else None,
|
||||
content=content if custom_template else None,
|
||||
args=args,
|
||||
header=[subject, "green"],
|
||||
)
|
||||
|
||||
def validate_duplicate_certificate(self):
|
||||
certificates = frappe.get_all(
|
||||
"LMS Certificate",
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"is_onboarding_complete",
|
||||
"column_break_zdel",
|
||||
"livecode_url",
|
||||
"certification_template",
|
||||
"course_settings_section",
|
||||
"search_placeholder",
|
||||
"column_break_iqxy",
|
||||
@@ -186,7 +187,7 @@
|
||||
{
|
||||
"fieldname": "section_break_szgq",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Class Settings"
|
||||
"label": "Batch Settings"
|
||||
},
|
||||
{
|
||||
"fieldname": "signup_settings_tab",
|
||||
@@ -316,12 +317,18 @@
|
||||
"fieldname": "show_dashboard",
|
||||
"fieldtype": "Check",
|
||||
"label": "Dashboard"
|
||||
},
|
||||
{
|
||||
"fieldname": "certification_template",
|
||||
"fieldtype": "Link",
|
||||
"label": "Certificate Email Template",
|
||||
"options": "Email Template"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2023-10-30 16:42:58.994359",
|
||||
"modified": "2023-11-01 22:38:38.380325",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Settings",
|
||||
|
||||
Reference in New Issue
Block a user