diff --git a/lms/lms/doctype/lms_certificate/lms_certificate.py b/lms/lms/doctype/lms_certificate/lms_certificate.py index 66fd3339..1ffe1f10 100644 --- a/lms/lms/doctype/lms_certificate/lms_certificate.py +++ b/lms/lms/doctype/lms_certificate/lms_certificate.py @@ -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", diff --git a/lms/lms/doctype/lms_settings/lms_settings.json b/lms/lms/doctype/lms_settings/lms_settings.json index abfbb361..2791f044 100644 --- a/lms/lms/doctype/lms_settings/lms_settings.json +++ b/lms/lms/doctype/lms_settings/lms_settings.json @@ -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", diff --git a/lms/templates/emails/certification.html b/lms/templates/emails/certification.html new file mode 100644 index 00000000..3d47b1b9 --- /dev/null +++ b/lms/templates/emails/certification.html @@ -0,0 +1,21 @@ +
+ {{ _("Dear ") }} {{ student_name }}, +
++ {{ _("I am delighted to inform you that you have successfully earned your certification for the {0} course. Congratulations!").format(frappe.bold(course_title)) }} +
++ {{ _("With this certification, you can now showcase your updated skills and share your achievement with your colleagues and on LinkedIn. To access your certificate, please click on the link provided below.") }} +
++ {{ _("Once again, congratulations on this significant accomplishment.")}} +
++ {{ _("Best Regards") }} +
\ No newline at end of file