calculate number of students in exam group

This commit is contained in:
Pranav Jerry 2023-04-05 22:12:08 +05:30
parent c1c18a7bbe
commit 5336db8796
Signed by: pranav
GPG Key ID: F1DCDC4FED0A0C5B
1 changed files with 6 additions and 3 deletions

View File

@ -7,19 +7,22 @@ from frappe.model.document import Document
class ExamGroup(Document):
def before_save(self):
self.number_of_students = 0
exams = frappe.db.get_list(
"Exam", filters={"date": self.date, "session": self.session}
"Exam", filters={"date": self.date, "session": self.session}, pluck="name"
)
if not exams:
frappe.throw("No exams found on given date and session")
for i in exams:
for exam_id in exams:
exam_child = frappe.new_doc("Exam Child")
exam_child.update(
{
"id": i["name"],
"id": exam_id,
"parent": self.name,
"parentfield": "exams",
"parenttype": self.doctype,
}
)
self.exams.append(exam_child)
exam = frappe.get_doc("Exam", exam_id)
self.number_of_students += len(exam.students)