From f9fd36f77e339a41eea5aa661ebe0ff04ea5d16b Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Wed, 19 Feb 2025 22:29:24 +0530 Subject: [PATCH] feat: cancel evaluations --- .../src/components/UpcomingEvaluations.vue | 70 +++++++++++++++++-- lms/lms/api.py | 37 ++++++++++ .../lms_certificate_request.json | 28 +++++++- lms/lms/utils.py | 12 +++- lms/patches.txt | 3 +- .../v2_0/update_certificate_request_status.py | 14 ++++ 6 files changed, 153 insertions(+), 11 deletions(-) create mode 100644 lms/patches/v2_0/update_certificate_request_status.py diff --git a/frontend/src/components/UpcomingEvaluations.vue b/frontend/src/components/UpcomingEvaluations.vue index 135ca913..d90fa55a 100644 --- a/frontend/src/components/UpcomingEvaluations.vue +++ b/frontend/src/components/UpcomingEvaluations.vue @@ -9,7 +9,7 @@
-
+
@@ -28,11 +28,33 @@
- - + + {{ evl.evaluator_name }}
+
+ + +
@@ -50,15 +72,23 @@ /> diff --git a/lms/lms/api.py b/lms/lms/api.py index 4a502628..74daf2e1 100644 --- a/lms/lms/api.py +++ b/lms/lms/api.py @@ -12,6 +12,7 @@ from frappe.translate import get_all_translations from frappe import _ from frappe.utils import ( get_datetime, + getdate, cint, flt, now, @@ -1228,3 +1229,39 @@ def get_notifications(filters): @frappe.whitelist(allow_guest=True) def is_guest_allowed(): return frappe.get_cached_value("LMS Settings", None, "allow_guest_access") + + +@frappe.whitelist() +def cancel_evaluation(evaluation): + evaluation = frappe._dict(evaluation) + + if evaluation.member != frappe.session.user: + return + + frappe.db.set_value("LMS Certificate Request", evaluation.name, "status", "Cancelled") + events = frappe.get_all( + "Event Participants", + { + "email": evaluation.member, + }, + ["parent", "name"], + ) + + for event in events: + info = frappe.db.get_value("Event", event.parent, ["starts_on", "subject"], as_dict=1) + date = str(info.starts_on).split(" ")[0] + + if ( + date == str(evaluation.date.format("YYYY-MM-DD")) + and evaluation.member_name in info.subject + ): + communication = frappe.db.get_value( + "Communication", + {"reference_doctype": "Event", "reference_name": event.parent}, + "name", + ) + if communication: + frappe.delete_doc("Communication", communication, ignore_permissions=True) + + frappe.delete_doc("Event Participants", event.name, ignore_permissions=True) + frappe.delete_doc("Event", event.parent, ignore_permissions=True) diff --git a/lms/lms/doctype/lms_certificate_request/lms_certificate_request.json b/lms/lms/doctype/lms_certificate_request/lms_certificate_request.json index f17cc999..ae59baf1 100644 --- a/lms/lms/doctype/lms_certificate_request/lms_certificate_request.json +++ b/lms/lms/doctype/lms_certificate_request/lms_certificate_request.json @@ -24,7 +24,8 @@ "google_meet_link", "column_break_ddyh", "start_time", - "end_time" + "end_time", + "status" ], "fields": [ { @@ -144,11 +145,19 @@ "fieldtype": "Data", "hidden": 1, "label": "Batch Title" + }, + { + "fieldname": "status", + "fieldtype": "Select", + "in_standard_filter": 1, + "label": "Status", + "options": "Upcoming\nCompleted\nCancelled", + "read_only": 1 } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2024-09-11 11:19:44.669132", + "modified": "2025-02-19 17:20:02.526294", "modified_by": "Administrator", "module": "LMS", "name": "LMS Certificate Request", @@ -204,6 +213,19 @@ ], "sort_field": "modified", "sort_order": "DESC", - "states": [], + "states": [ + { + "color": "Blue", + "title": "Upcoming" + }, + { + "color": "Green", + "title": "Completed" + }, + { + "color": "Red", + "title": "Cancelled" + } + ], "title_field": "member_name" } \ No newline at end of file diff --git a/lms/lms/utils.py b/lms/lms/utils.py index 4da39eb4..5a6147b9 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -874,8 +874,18 @@ def get_upcoming_evals(student, courses): "member": student, "course": ["in", courses], "date": [">=", frappe.utils.nowdate()], + "status": "Upcoming", }, - ["date", "start_time", "course", "evaluator", "google_meet_link"], + [ + "name", + "date", + "start_time", + "course", + "evaluator", + "google_meet_link", + "member", + "member_name", + ], order_by="date", ) diff --git a/lms/patches.txt b/lms/patches.txt index 5dd122a8..5a1c3eb3 100644 --- a/lms/patches.txt +++ b/lms/patches.txt @@ -100,4 +100,5 @@ lms.patches.v2_0.convert_quiz_duration_to_minutes lms.patches.v2_0.allow_guest_access #05-02-2025 lms.patches.v2_0.migrate_batch_student_data #10-02-2025 lms.patches.v2_0.delete_old_enrollment_doctypes -lms.patches.v2_0.delete_unused_custom_fields \ No newline at end of file +lms.patches.v2_0.delete_unused_custom_fields +lms.patches.v2_0.update_certificate_request_status \ No newline at end of file diff --git a/lms/patches/v2_0/update_certificate_request_status.py b/lms/patches/v2_0/update_certificate_request_status.py new file mode 100644 index 00000000..7d01788c --- /dev/null +++ b/lms/patches/v2_0/update_certificate_request_status.py @@ -0,0 +1,14 @@ +import frappe +from frappe.utils import getdate + + +def execute(): + evaluations = frappe.get_all("LMS Certificate Request", fields=["name", "date"]) + + for evaluation in evaluations: + if evaluation.date > getdate(): + frappe.db.set_value("LMS Certificate Request", evaluation.name, "status", "Upcoming") + else: + frappe.db.set_value( + "LMS Certificate Request", evaluation.name, "status", "Completed" + )