added hall allocation
allocates exam halls to exam group object
This commit is contained in:
parent
5336db8796
commit
d11add1354
|
@ -1,8 +1,26 @@
|
|||
// Copyright (c) 2023, CSE 2020 Batch and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
// frappe.ui.form.on("Exam Group", {
|
||||
// refresh(frm) {
|
||||
|
||||
// },
|
||||
// });
|
||||
frappe.ui.form.on("Exam Group", {
|
||||
refresh(frm) {
|
||||
frm.add_custom_button("Allocate exam halls", () => {
|
||||
frm.trigger("allocate_exam_halls");
|
||||
});
|
||||
frm.change_custom_button_type("Allocate exam halls", null, "primary");
|
||||
},
|
||||
allocate_exam_halls(frm) {
|
||||
frappe.db
|
||||
.insert({
|
||||
doctype: "Hall Allocation",
|
||||
date: frm.doc.date,
|
||||
session: frm.doc.session,
|
||||
exam_group: frm.doc.name,
|
||||
})
|
||||
.then((doc) => {
|
||||
frm.set_value("hall_allocation", doc.name).then(() => {
|
||||
frm.save();
|
||||
frappe.set_route("Form", "Hall Allocation", doc.name);
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"session",
|
||||
"exams",
|
||||
"number_of_students",
|
||||
"exam_halls"
|
||||
"hall_allocation"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
|
@ -22,12 +22,6 @@
|
|||
"label": "Exams",
|
||||
"options": "Exam Child"
|
||||
},
|
||||
{
|
||||
"fieldname": "exam_halls",
|
||||
"fieldtype": "Table MultiSelect",
|
||||
"label": "Exam halls",
|
||||
"options": "Exam Hall Child"
|
||||
},
|
||||
{
|
||||
"fieldname": "date",
|
||||
"fieldtype": "Date",
|
||||
|
@ -48,11 +42,17 @@
|
|||
"fieldtype": "Int",
|
||||
"label": "Number of students",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "hall_allocation",
|
||||
"fieldtype": "Link",
|
||||
"label": "Hall Allocation",
|
||||
"options": "Hall Allocation"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2023-03-26 16:39:58.804963",
|
||||
"modified": "2023-04-06 11:31:06.650210",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Exam Helper",
|
||||
"name": "Exam Group",
|
||||
|
|
|
@ -6,7 +6,7 @@ from frappe.model.document import Document
|
|||
|
||||
|
||||
class ExamGroup(Document):
|
||||
def before_save(self):
|
||||
def before_insert(self):
|
||||
self.number_of_students = 0
|
||||
exams = frappe.db.get_list(
|
||||
"Exam", filters={"date": self.date, "session": self.session}, pluck="name"
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
// Copyright (c) 2023, CSE 2020 Batch and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
// frappe.ui.form.on("Hall Allocation", {
|
||||
// refresh(frm) {
|
||||
|
||||
// },
|
||||
// });
|
|
@ -0,0 +1,83 @@
|
|||
{
|
||||
"actions": [],
|
||||
"allow_rename": 1,
|
||||
"autoname": "format:ALLOCATION-{####}-{date}-{session}",
|
||||
"creation": "2023-04-06 10:53:24.067133",
|
||||
"default_view": "List",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"date",
|
||||
"session",
|
||||
"exam_group",
|
||||
"allocated_rooms",
|
||||
"amended_from"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "date",
|
||||
"fieldtype": "Date",
|
||||
"in_list_view": 1,
|
||||
"label": "Date",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "session",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Session",
|
||||
"options": "Forenoon\nAfternoon",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "amended_from",
|
||||
"fieldtype": "Link",
|
||||
"label": "Amended From",
|
||||
"no_copy": 1,
|
||||
"options": "Hall Allocation",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"description": "Exam Halls allocated for the exam. Autogenerated by Exam Helper the first time it is created. Can be manually edited if needed",
|
||||
"fieldname": "allocated_rooms",
|
||||
"fieldtype": "Table MultiSelect",
|
||||
"label": "Allocated rooms",
|
||||
"options": "Exam Hall Child"
|
||||
},
|
||||
{
|
||||
"fieldname": "exam_group",
|
||||
"fieldtype": "Link",
|
||||
"label": "Exam Group",
|
||||
"options": "Exam Group",
|
||||
"reqd": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-04-06 11:53:04.000373",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Exam Helper",
|
||||
"name": "Hall Allocation",
|
||||
"naming_rule": "Expression",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
# Copyright (c) 2023, CSE 2020 Batch and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
class HallAllocation(Document):
|
||||
def before_insert(self):
|
||||
"""automatically allocate exam halls to the exam"""
|
||||
exam_halls = frappe.get_list("Exam Hall", pluck="name")
|
||||
exam_group = frappe.get_doc("Exam Group", self.exam_group)
|
||||
number_of_students = exam_group.number_of_students
|
||||
print(vars(self))
|
||||
for exam_hall in exam_halls:
|
||||
if number_of_students <= 0:
|
||||
break
|
||||
print(vars(self))
|
||||
exam_hall = frappe.get_doc("Exam Hall", exam_hall)
|
||||
number_of_students -= exam_hall.seating_capacity
|
||||
e = frappe.new_doc("Exam Hall Child")
|
||||
e.update(
|
||||
{
|
||||
"id": exam_hall.name,
|
||||
"parent": self.name,
|
||||
"parentfield": "allocated_rooms",
|
||||
"parenttype": self.doctype,
|
||||
}
|
||||
)
|
||||
# e.save()
|
||||
print(vars(self))
|
||||
self.allocated_rooms.append(e)
|
|
@ -0,0 +1,9 @@
|
|||
# Copyright (c) 2023, CSE 2020 Batch and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
|
||||
|
||||
class TestHallAllocation(FrappeTestCase):
|
||||
pass
|
Loading…
Reference in New Issue