diff --git a/lms/lms/doctype/lms_certificate/lms_certificate.py b/lms/lms/doctype/lms_certificate/lms_certificate.py index 5e4f8688..232770e6 100644 --- a/lms/lms/doctype/lms_certificate/lms_certificate.py +++ b/lms/lms/doctype/lms_certificate/lms_certificate.py @@ -9,7 +9,10 @@ from lms.lms.utils import is_certified class LMSCertificate(Document): - def before_insert(self): + def validate(self): + self.validate_duplicate_certificate() + + def validate_duplicate_certificate(self): certificates = frappe.get_all( "LMS Certificate", {"member": self.member, "course": self.course} ) @@ -20,6 +23,18 @@ class LMSCertificate(Document): _("{0} is already certified for the course {1}").format(full_name, course_name) ) + def after_insert(self): + share = frappe.get_doc( + { + "doctype": "DocShare", + "read": 1, + "share_doctype": "LMS Certificate", + "share_name": self.name, + "user": self.member, + } + ) + share.save(ignore_permissions=True) + @frappe.whitelist() def create_certificate(course):