From b6cfcd797bb828b384ee0f16562c0703d3f8daf6 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Tue, 11 Feb 2025 14:55:44 +0530 Subject: [PATCH] fix: pluck only member for to validate batch course membership --- lms/lms/doctype/lms_batch/lms_batch.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/lms/lms/doctype/lms_batch/lms_batch.py b/lms/lms/doctype/lms_batch/lms_batch.py index 328ebdcd..22a0c2f6 100644 --- a/lms/lms/doctype/lms_batch/lms_batch.py +++ b/lms/lms/doctype/lms_batch/lms_batch.py @@ -41,16 +41,6 @@ class LMSBatch(Document): if self.end_date < self.start_date: frappe.throw(_("Batch end date cannot be before the batch start date")) - def validate_duplicate_students(self): - students = [row.student for row in self.students] - duplicates = {student for student in students if students.count(student) > 1} - if len(duplicates): - frappe.throw( - _("Student {0} has already been added to this batch.").format( - frappe.bold(next(iter(duplicates))) - ) - ) - def validate_duplicate_courses(self): courses = [row.course for row in self.courses] duplicates = {course for course in courses if courses.count(course) > 1} @@ -88,9 +78,7 @@ class LMSBatch(Document): frappe.throw(_("Evaluation end date cannot be less than the batch end date.")) def validate_membership(self): - members = frappe.get_all( - "LMS Batch Enrollment", filters={"batch": self.name}, pluck=["member"] - ) + members = frappe.get_all("LMS Batch Enrollment", {"batch": self.name}, pluck="member") for course in self.courses: for member in members: if not frappe.db.exists( @@ -102,7 +90,8 @@ class LMSBatch(Document): enrollment.save() def validate_seats_left(self): - if cint(self.seat_count) < len(self.students): + students = frappe.db.count("LMS Batch Enrollment", {"batch": self.name}) + if cint(self.seat_count) < students: frappe.throw(_("There are no seats available in this batch.")) def validate_timetable(self):