style: formattin

This commit is contained in:
Jannat Patel
2025-02-10 16:16:11 +05:30
parent ab98884f77
commit 4ee2bfcf32
4 changed files with 55 additions and 30 deletions

View File

@@ -88,11 +88,15 @@ class LMSBatch(Document):
frappe.throw(_("Evaluation end date cannot be less than the batch end date.")) frappe.throw(_("Evaluation end date cannot be less than the batch end date."))
def validate_membership(self): def validate_membership(self):
members = frappe.get_all('LMS Batch Enrollment', filters={'batch': self.name}, pluck=['member']) members = frappe.get_all(
"LMS Batch Enrollment", filters={"batch": self.name}, pluck=["member"]
)
for course in self.courses: for course in self.courses:
for member in members: for member in members:
if not frappe.db.exists('LMS Enrollment', {'course': course.course, 'member': member}): if not frappe.db.exists(
enrollment = frappe.new_doc('LMS Enrollment') "LMS Enrollment", {"course": course.course, "member": member}
):
enrollment = frappe.new_doc("LMS Enrollment")
enrollment.course = course.course enrollment.course = course.course
enrollment.member = member enrollment.member = member
enrollment.save() enrollment.save()

View File

@@ -8,7 +8,6 @@ from frappe.email.doctype.email_template.email_template import get_email_templat
class LMSBatchEnrollment(Document): class LMSBatchEnrollment(Document):
def after_insert(self): def after_insert(self):
self.send_confirmation_email() self.send_confirmation_email()
self.add_member_to_live_class() self.add_member_to_live_class()
@@ -18,7 +17,9 @@ class LMSBatchEnrollment(Document):
self.validate_course_enrollment() self.validate_course_enrollment()
def validate_duplicate_members(self): def validate_duplicate_members(self):
if frappe.db.exists("LMS Batch Enrollment", {"batch": self.batch, "member": self.member}): if frappe.db.exists(
"LMS Batch Enrollment", {"batch": self.batch, "member": self.member}
):
frappe.throw(_("Member already enrolled in this batch")) frappe.throw(_("Member already enrolled in this batch"))
def validate_course_enrollment(self): def validate_course_enrollment(self):
@@ -41,9 +42,8 @@ class LMSBatchEnrollment(Document):
outgoing_email_account = frappe.get_cached_value( outgoing_email_account = frappe.get_cached_value(
"Email Account", {"default_outgoing": 1, "enable_outgoing": 1}, "name" "Email Account", {"default_outgoing": 1, "enable_outgoing": 1}, "name"
) )
if ( if not self.confirmation_email_sent and (
not self.confirmation_email_sent outgoing_email_account or frappe.conf.get("mail_login")
and (outgoing_email_account or frappe.conf.get("mail_login"))
): ):
self.send_mail() self.send_mail()
self.confirmation_email_sent = 1 self.confirmation_email_sent = 1
@@ -54,7 +54,12 @@ class LMSBatchEnrollment(Document):
custom_template = frappe.db.get_single_value( custom_template = frappe.db.get_single_value(
"LMS Settings", "batch_confirmation_template" "LMS Settings", "batch_confirmation_template"
) )
batch = frappe.db.get_value("LMS Batch", self.batch, ["name", "title", "start_date", "start_time", "medium"], as_dict=1) batch = frappe.db.get_value(
"LMS Batch",
self.batch,
["name", "title", "start_date", "start_time", "medium"],
as_dict=1,
)
args = { args = {
"title": batch.title, "title": batch.title,
"student_name": self.member_name, "student_name": self.member_name,
@@ -96,4 +101,4 @@ class LMSBatchEnrollment(Document):
"parenttype": "Event", "parenttype": "Event",
"parentfield": "event_participants", "parentfield": "event_participants",
} }
).save() ).save()

View File

@@ -1226,9 +1226,9 @@ def get_batch_details(batch):
batch_details.courses = frappe.get_all( batch_details.courses = frappe.get_all(
"Batch Course", filters={"parent": batch}, fields=["course", "title", "evaluator"] "Batch Course", filters={"parent": batch}, fields=["course", "title", "evaluator"]
) )
batch_details.students = frappe.get_all("LMS Batch Enrollment", { batch_details.students = frappe.get_all(
"batch": batch "LMS Batch Enrollment", {"batch": batch}, pluck="member"
}, pluck='member') )
if batch_details.paid_batch and batch_details.start_date >= getdate(): if batch_details.paid_batch and batch_details.start_date >= getdate():
batch_details.amount, batch_details.currency = check_multicurrency( batch_details.amount, batch_details.currency = check_multicurrency(
@@ -1718,16 +1718,20 @@ def enroll_in_batch(batch, payment_name=None):
if not frappe.db.exists( if not frappe.db.exists(
"LMS Batch Enrollment", {"batch": batch, "member": frappe.session.user} "LMS Batch Enrollment", {"batch": batch, "member": frappe.session.user}
): ):
batch_doc = frappe.db.get_value('LMS Batch', batch, ['name', 'seat_count'], as_dict=True) batch_doc = frappe.db.get_value(
"LMS Batch", batch, ["name", "seat_count"], as_dict=True
)
students = frappe.db.count("LMS Batch Enrollment", {"batch": batch}) students = frappe.db.count("LMS Batch Enrollment", {"batch": batch})
if batch_doc.seat_count and students >= batch_doc.seat_count: if batch_doc.seat_count and students >= batch_doc.seat_count:
frappe.throw(_("The batch is full. Please contact the Administrator.")) frappe.throw(_("The batch is full. Please contact the Administrator."))
new_student = frappe.new_doc("LMS Batch Enrollment") new_student = frappe.new_doc("LMS Batch Enrollment")
new_student.update({ new_student.update(
"member": frappe.session.user, {
"batch": batch, "member": frappe.session.user,
}) "batch": batch,
}
)
if payment_name: if payment_name:
payment = frappe.db.get_value( payment = frappe.db.get_value(

View File

@@ -1,17 +1,29 @@
import frappe import frappe
def execute(): def execute():
students = frappe.get_all("Batch Student", fields=["student", "student_name", "username", "payment", "source", "parent", "confirmation_email_sent"]) students = frappe.get_all(
"Batch Student",
fields=[
"student",
"student_name",
"username",
"payment",
"source",
"parent",
"confirmation_email_sent",
],
)
for student in students: for student in students:
doc = frappe.new_doc("LMS Batch Enrollment") doc = frappe.new_doc("LMS Batch Enrollment")
doc.member = student.student doc.member = student.student
doc.member_name = student.student_name doc.member_name = student.student_name
doc.member_username = student.username doc.member_username = student.username
doc.payment = student.payment doc.payment = student.payment
doc.source = student.source doc.source = student.source
doc.batch = student.parent doc.batch = student.parent
doc.confirmation_email_sent = student.confirmation_email_sent doc.confirmation_email_sent = student.confirmation_email_sent
doc.save() doc.save()
frappe.delete_doc("DocType", "Batch Student") frappe.delete_doc("DocType", "Batch Student")