diff --git a/lms/lms/doctype/lms_certificate/lms_certificate.js b/lms/lms/doctype/lms_certificate/lms_certificate.js index f68937c9d..74cfeea83 100644 --- a/lms/lms/doctype/lms_certificate/lms_certificate.js +++ b/lms/lms/doctype/lms_certificate/lms_certificate.js @@ -10,6 +10,14 @@ frappe.ui.form.on("LMS Certificate", { }, }; }); + + frm.set_query("template", function (doc) { + return { + filters: { + doc_type: "LMS Certificate", + }, + }; + }); }, refresh: (frm) => { if (frm.doc.name) diff --git a/lms/lms/doctype/lms_certificate/lms_certificate.json b/lms/lms/doctype/lms_certificate/lms_certificate.json index 8033cd8f6..83f4ba528 100644 --- a/lms/lms/doctype/lms_certificate/lms_certificate.json +++ b/lms/lms/doctype/lms_certificate/lms_certificate.json @@ -8,11 +8,12 @@ "course", "member", "member_name", - "published", + "template", "column_break_3", "issue_date", "expiry_date", - "batch_name" + "batch_name", + "published" ], "fields": [ { @@ -67,11 +68,18 @@ "fieldname": "published", "fieldtype": "Check", "label": "Publish on Participant Page" + }, + { + "fieldname": "template", + "fieldtype": "Link", + "label": "Template", + "options": "Print Format", + "reqd": 1 } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-09-13 11:03:23.479255", + "modified": "2023-10-25 12:20:56.091979", "modified_by": "Administrator", "module": "LMS", "name": "LMS Certificate", diff --git a/lms/lms/doctype/lms_certificate/lms_certificate.py b/lms/lms/doctype/lms_certificate/lms_certificate.py index daa400e4e..66fd33392 100644 --- a/lms/lms/doctype/lms_certificate/lms_certificate.py +++ b/lms/lms/doctype/lms_certificate/lms_certificate.py @@ -48,6 +48,15 @@ def create_certificate(course): if expires_after_yrs: expiry_date = add_years(nowdate(), expires_after_yrs) + default_certificate_template = frappe.db.get_value( + "Property Setter", + { + "doc_type": "LMS Certificate", + "property": "default_print_format", + }, + "value", + ) + certificate = frappe.get_doc( { "doctype": "LMS Certificate", @@ -55,6 +64,7 @@ def create_certificate(course): "course": course, "issue_date": nowdate(), "expiry_date": expiry_date, + "template": default_certificate_template, } ) certificate.save(ignore_permissions=True) diff --git a/lms/patches.txt b/lms/patches.txt index 5a28133a8..a2c0dcba3 100644 --- a/lms/patches.txt +++ b/lms/patches.txt @@ -74,4 +74,5 @@ execute:frappe.permissions.reset_perms("LMS Enrollment") lms.patches.v1_0.create_student_role lms.patches.v1_0.mark_confirmation_for_batch_students lms.patches.v1_0.create_quiz_questions -lms.patches.v1_0.add_default_marks #16-10-2023 \ No newline at end of file +lms.patches.v1_0.add_default_marks #16-10-2023 +lms.patches.v1_0.add_certificate_template #25-10-2023 \ No newline at end of file diff --git a/lms/patches/v1_0/add_certificate_template.py b/lms/patches/v1_0/add_certificate_template.py new file mode 100644 index 000000000..a38b44665 --- /dev/null +++ b/lms/patches/v1_0/add_certificate_template.py @@ -0,0 +1,19 @@ +import frappe + + +def execute(): + default_certificate_template = frappe.db.get_value( + "Property Setter", + { + "doc_type": "LMS Certificate", + "property": "default_print_format", + }, + "value", + ) + + if frappe.db.exists("Print Format", default_certificate_template): + certificates = frappe.get_all("LMS Certificate", pluck="name") + for certificate in certificates: + frappe.db.set_value( + "LMS Certificate", certificate, "template", default_certificate_template + ) diff --git a/lms/www/courses/certificate.py b/lms/www/courses/certificate.py index 91e4de533..2931cedb9 100644 --- a/lms/www/courses/certificate.py +++ b/lms/www/courses/certificate.py @@ -16,7 +16,7 @@ def get_context(context): context.doc = frappe.db.get_value( "LMS Certificate", certificate_name, - ["name", "member", "issue_date", "expiry_date", "course"], + ["name", "member", "issue_date", "expiry_date", "course", "template"], as_dict=True, ) @@ -31,7 +31,10 @@ def get_context(context): ) context.url = f"{get_url()}/courses/{context.course.name}/{context.doc.name}" - print_format = get_print_format() + if context.doc.template: + print_format = context.doc.template + else: + print_format = get_print_format() template = frappe.db.get_value( "Print Format", print_format, ["html", "css"], as_dict=True