diff --git a/lms/lms/doctype/lms_certificate_request/lms_certificate_request.py b/lms/lms/doctype/lms_certificate_request/lms_certificate_request.py index 61e95d06..38fc472e 100644 --- a/lms/lms/doctype/lms_certificate_request/lms_certificate_request.py +++ b/lms/lms/doctype/lms_certificate_request/lms_certificate_request.py @@ -12,6 +12,10 @@ class LMSCertificateRequest(Document): def validate(self): self.validate_if_existing_requests() + def after_insert(self): + if frappe.db.get_single_value("LMS Settings", "send_calendar_invite_for_evaluations"): + self.create_event() + def validate_if_existing_requests(self): existing_requests = frappe.get_all( "LMS Certificate Request", @@ -30,6 +34,46 @@ class LMSCertificateRequest(Document): ) ) + def create_event(self): + calendar = frappe.db.get_value("Google Calendar", {"user": self.evaluator}, "name") + + if calendar: + event = frappe.get_doc( + { + "doctype": "Event", + "subject": f"Evaluation of {self.member_name}", + "starts_on": f"{self.date} {self.start_time}", + "ends_on": f"{self.date} {self.end_time}", + } + ) + event.save() + + participants = [self.member, self.evaluator] + for participant in participants: + contact_name = frappe.db.get_value("Contact", {"email_id": participant}, "name") + frappe.get_doc( + { + "doctype": "Event Participants", + "reference_doctype": "Contact", + "reference_docname": contact_name, + "email": participant, + "parent": event.name, + "parenttype": "Event", + "parentfield": "event_participants", + } + ).save() + + event.reload() + event.update( + { + "sync_with_google_calendar": 1, + "add_video_conferencing": 1, + "google_calendar": calendar, + } + ) + + event.save() + @frappe.whitelist() def create_certificate_request(course, date, day, start_time, end_time): diff --git a/lms/lms/doctype/lms_course/lms_course.json b/lms/lms/doctype/lms_course/lms_course.json index f2e4ce4a..cb656a26 100644 --- a/lms/lms/doctype/lms_course/lms_course.json +++ b/lms/lms/doctype/lms_course/lms_course.json @@ -261,7 +261,7 @@ } ], "make_attachments_public": 1, - "modified": "2022-09-14 13:26:53.153822", + "modified": "2023-02-16 10:11:17.557472", "modified_by": "Administrator", "module": "LMS", "name": "LMS Course", @@ -295,7 +295,6 @@ } ], "search_fields": "title", - "show_title_field_in_link": 1, "sort_field": "creation", "sort_order": "DESC", "states": [], diff --git a/lms/lms/doctype/lms_settings/lms_settings.json b/lms/lms/doctype/lms_settings/lms_settings.json index fe272759..e2f7d108 100644 --- a/lms/lms/doctype/lms_settings/lms_settings.json +++ b/lms/lms/doctype/lms_settings/lms_settings.json @@ -5,14 +5,18 @@ "editable_grid": 1, "engine": "InnoDB", "field_order": [ - "search_placeholder", - "portal_course_creation", "default_home", "is_onboarding_complete", + "column_break_zdel", + "send_calendar_invite_for_evaluations", + "force_profile_completion", + "section_break_szgq", + "search_placeholder", + "portal_course_creation", "column_break_2", "custom_certificate_template", "livecode_url", - "force_profile_completion", + "signup_settings_tab", "signup_settings_section", "terms_of_use", "terms_page", @@ -23,6 +27,7 @@ "column_break_12", "cookie_policy", "cookie_policy_page", + "mentor_request_tab", "mentor_request_section", "mentor_request_creation", "mentor_request_status_update" @@ -82,8 +87,7 @@ }, { "fieldname": "signup_settings_section", - "fieldtype": "Section Break", - "label": "Signup Settings" + "fieldtype": "Section Break" }, { "default": "0", @@ -152,12 +156,36 @@ "fieldname": "default_home", "fieldtype": "Check", "label": "Make LMS the default home" + }, + { + "fieldname": "column_break_zdel", + "fieldtype": "Column Break" + }, + { + "default": "0", + "fieldname": "send_calendar_invite_for_evaluations", + "fieldtype": "Check", + "label": "Send calendar invite for evaluations" + }, + { + "fieldname": "section_break_szgq", + "fieldtype": "Section Break" + }, + { + "fieldname": "signup_settings_tab", + "fieldtype": "Tab Break", + "label": "Signup Settings" + }, + { + "fieldname": "mentor_request_tab", + "fieldtype": "Tab Break", + "label": "Mentor Request" } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2023-02-07 19:53:46.073914", + "modified": "2023-02-15 17:13:11.802215", "modified_by": "Administrator", "module": "LMS", "name": "LMS Settings", diff --git a/lms/lms/doctype/lms_settings/lms_settings.py b/lms/lms/doctype/lms_settings/lms_settings.py index d8afde6e..4d90bc41 100644 --- a/lms/lms/doctype/lms_settings/lms_settings.py +++ b/lms/lms/doctype/lms_settings/lms_settings.py @@ -4,7 +4,38 @@ import frappe from frappe import _ from frappe.model.document import Document +from frappe.utils import get_url_to_list class LMSSettings(Document): - pass + def validate(self): + self.validate_google_settings() + + def validate_google_settings(self): + if self.send_calendar_invite_for_evaluations: + google_settings = frappe.get_single("Google Settings") + + if not google_settings.enable: + frappe.throw( + _("Enable Google API in Google Settings to send calendar invites for evaluations.") + ) + + if not google_settings.client_id or not google_settings.client_secret: + frappe.throw( + _( + "Enter Client Id and Client Secret in Google Settings to send calendar invites for evaluations." + ) + ) + + calendars = frappe.db.count("Google Calendar") + if not calendars: + frappe.throw( + _( + "Please add {1} for {3} to send calendar invites for evaluations." + ).format( + get_url_to_list("Google Calendar"), + frappe.bold("Google Calendar"), + get_url_to_list("Course Evaluator"), + frappe.bold("Course Evaluator"), + ) + )