Course Scheduling Tool (#11676)
* [education] Fix Course Scheduling Tool * minor
This commit is contained in:
parent
476c66d699
commit
6ca6a69070
@ -1,20 +1,39 @@
|
|||||||
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
|
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
cur_frm.add_fetch("student_group", "program", "program");
|
|
||||||
cur_frm.add_fetch("student_group", "course", "course");
|
|
||||||
cur_frm.add_fetch("student_group", "academic_year", "academic_year");
|
|
||||||
cur_frm.add_fetch("student_group", "academic_term", "academic_term");
|
|
||||||
|
|
||||||
frappe.ui.form.on("Course Scheduling Tool", {
|
frappe.ui.form.on('Course Scheduling Tool', {
|
||||||
|
setup(frm) {
|
||||||
refresh: function(frm) {
|
frm.add_fetch('student_group', 'program', 'program');
|
||||||
|
frm.add_fetch('student_group', 'course', 'course');
|
||||||
|
frm.add_fetch('student_group', 'academic_year', 'academic_year');
|
||||||
|
frm.add_fetch('student_group', 'academic_term', 'academic_term');
|
||||||
|
},
|
||||||
|
refresh(frm) {
|
||||||
frm.disable_save();
|
frm.disable_save();
|
||||||
frm.page.set_primary_action(__("Schedule Course"), function() {
|
frm.page.set_primary_action(__('Schedule Course'), () => {
|
||||||
frappe.call({
|
frm.call('schedule_course')
|
||||||
method: "schedule_course",
|
.then(r => {
|
||||||
doc: frm.doc
|
if (!r.message) {
|
||||||
})
|
frappe.throw(__('There were errors creating Course Schedule'));
|
||||||
|
}
|
||||||
|
const { course_schedules } = r.message;
|
||||||
|
if (course_schedules) {
|
||||||
|
const html = `
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<caption>${__('Following course schedules were created')}</caption>
|
||||||
|
<thead><tr><th>${__("Course")}</th><th>${__("Date")}</th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
${course_schedules.map(
|
||||||
|
c => `<tr><td><a href="#Form/Course Schedule/${c.name}">${c.name}</a></td>
|
||||||
|
<td>${c.schedule_date}</td></tr>`
|
||||||
|
).join('')}
|
||||||
|
</tbody>
|
||||||
|
</table>`
|
||||||
|
|
||||||
|
frappe.msgprint(html);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
@ -476,7 +476,7 @@
|
|||||||
"bold": 0,
|
"bold": 0,
|
||||||
"collapsible": 0,
|
"collapsible": 0,
|
||||||
"columns": 0,
|
"columns": 0,
|
||||||
"fieldname": "rechedule",
|
"fieldname": "reschedule",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"hidden": 0,
|
"hidden": 0,
|
||||||
"ignore_user_permissions": 0,
|
"ignore_user_permissions": 0,
|
||||||
@ -485,7 +485,7 @@
|
|||||||
"in_global_search": 0,
|
"in_global_search": 0,
|
||||||
"in_list_view": 0,
|
"in_list_view": 0,
|
||||||
"in_standard_filter": 0,
|
"in_standard_filter": 0,
|
||||||
"label": "Rechedule",
|
"label": "Reschedule",
|
||||||
"length": 0,
|
"length": 0,
|
||||||
"no_copy": 0,
|
"no_copy": 0,
|
||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
@ -602,7 +602,7 @@
|
|||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 0,
|
"max_attachments": 0,
|
||||||
"menu_index": 0,
|
"menu_index": 0,
|
||||||
"modified": "2017-06-30 08:21:47.696063",
|
"modified": "2017-11-21 16:47:58.091740",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Schools",
|
"module": "Schools",
|
||||||
"name": "Course Scheduling Tool",
|
"name": "Course Scheduling Tool",
|
||||||
|
@ -10,9 +10,11 @@ from frappe.model.document import Document
|
|||||||
from frappe.utils import add_days, getdate
|
from frappe.utils import add_days, getdate
|
||||||
from erpnext.schools.utils import OverlapError
|
from erpnext.schools.utils import OverlapError
|
||||||
|
|
||||||
|
|
||||||
class CourseSchedulingTool(Document):
|
class CourseSchedulingTool(Document):
|
||||||
|
|
||||||
def schedule_course(self):
|
def schedule_course(self):
|
||||||
"""Creates course schedules as per specified parametes"""
|
"""Creates course schedules as per specified parameters"""
|
||||||
|
|
||||||
course_schedules = []
|
course_schedules = []
|
||||||
course_schedules_errors = []
|
course_schedules_errors = []
|
||||||
@ -21,60 +23,72 @@ class CourseSchedulingTool(Document):
|
|||||||
|
|
||||||
self.validate_mandatory()
|
self.validate_mandatory()
|
||||||
self.validate_date()
|
self.validate_date()
|
||||||
self.instructor_name= frappe.db.get_value("Instructor", self.instructor, "instructor_name")
|
self.instructor_name = frappe.db.get_value(
|
||||||
|
"Instructor", self.instructor, "instructor_name")
|
||||||
|
|
||||||
|
group_based_on, course = frappe.db.get_value(
|
||||||
|
"Student Group", self.student_group, ["group_based_on", "course"])
|
||||||
|
|
||||||
group_based_on, course = frappe.db.get_value("Student Group", self.student_group, ["group_based_on", "course"])
|
|
||||||
if group_based_on == "Course":
|
if group_based_on == "Course":
|
||||||
self.course = course
|
self.course = course
|
||||||
|
|
||||||
if self.rechedule:
|
if self.reschedule:
|
||||||
rescheduled, reschedule_errors = self.delete_course_schedule(rescheduled, reschedule_errors)
|
rescheduled, reschedule_errors = self.delete_course_schedule(
|
||||||
|
rescheduled, reschedule_errors)
|
||||||
|
|
||||||
date = self.course_start_date
|
date = self.course_start_date
|
||||||
while(date < self.course_end_date):
|
while date < self.course_end_date:
|
||||||
if self.day == calendar.day_name[getdate(date).weekday()]:
|
if self.day == calendar.day_name[getdate(date).weekday()]:
|
||||||
course_schedule = self.make_course_schedule(date)
|
course_schedule = self.make_course_schedule(date)
|
||||||
try:
|
try:
|
||||||
|
print('pass')
|
||||||
course_schedule.save()
|
course_schedule.save()
|
||||||
except OverlapError:
|
except OverlapError:
|
||||||
|
print('fail')
|
||||||
course_schedules_errors.append(date)
|
course_schedules_errors.append(date)
|
||||||
else:
|
else:
|
||||||
course_schedules.append(course_schedule.name + " on " + date)
|
course_schedules.append(course_schedule)
|
||||||
|
|
||||||
date = add_days(date, 7)
|
date = add_days(date, 7)
|
||||||
else:
|
else:
|
||||||
date = add_days(date, 1)
|
date = add_days(date, 1)
|
||||||
|
|
||||||
frappe.local.message_log = []
|
return dict(
|
||||||
if course_schedules:
|
course_schedules=course_schedules,
|
||||||
frappe.msgprint(_("Course Schedules created:") + "\n" + "\n".join(course_schedules))
|
course_schedules_errors=course_schedules_errors,
|
||||||
if course_schedules_errors:
|
rescheduled=rescheduled,
|
||||||
frappe.msgprint(_("There were errors while scheduling course on :") + "\n" + "\n".join(course_schedules_errors))
|
reschedule_errors=reschedule_errors
|
||||||
if rescheduled:
|
)
|
||||||
frappe.msgprint(_("Course Schedules deleted:") + "\n" + "\n".join(rescheduled))
|
|
||||||
if reschedule_errors:
|
|
||||||
frappe.msgprint(_("There were errors while deleting following schedules:") + "\n" + "\n".join(reschedule_errors))
|
|
||||||
|
|
||||||
def validate_mandatory(self):
|
def validate_mandatory(self):
|
||||||
"""Validates all mandatory fields"""
|
"""Validates all mandatory fields"""
|
||||||
|
|
||||||
fields = ['course', 'room', 'instructor', 'from_time', 'to_time', 'course_start_date', 'course_end_date', 'day']
|
fields = ['course', 'room', 'instructor', 'from_time',
|
||||||
|
'to_time', 'course_start_date', 'course_end_date', 'day']
|
||||||
for d in fields:
|
for d in fields:
|
||||||
if not self.get(d):
|
if not self.get(d):
|
||||||
frappe.throw(_("{0} is mandatory").format(self.meta.get_label(d)))
|
frappe.throw(_("{0} is mandatory").format(
|
||||||
|
self.meta.get_label(d)))
|
||||||
|
|
||||||
def validate_date(self):
|
def validate_date(self):
|
||||||
"""Validates if Course Start Date is greater than Course End Date"""
|
"""Validates if Course Start Date is greater than Course End Date"""
|
||||||
if self.course_start_date > self.course_end_date:
|
if self.course_start_date > self.course_end_date:
|
||||||
frappe.throw("Course Start Date cannot be greater than Course End Date.")
|
frappe.throw(
|
||||||
|
"Course Start Date cannot be greater than Course End Date.")
|
||||||
|
|
||||||
def delete_course_schedule(self, rescheduled, reschedule_errors):
|
def delete_course_schedule(self, rescheduled, reschedule_errors):
|
||||||
"""Delete all course schedule within the Date range and specified filters"""
|
"""Delete all course schedule within the Date range and specified filters"""
|
||||||
schedules = frappe.get_list("Course Schedule", fields=["name", "schedule_date"], filters =
|
|
||||||
[["student_group", "=", self.student_group],
|
schedules = frappe.get_list("Course Schedule",
|
||||||
|
fields=["name", "schedule_date"],
|
||||||
|
filters=[
|
||||||
|
["student_group", "=", self.student_group],
|
||||||
["course", "=", self.course],
|
["course", "=", self.course],
|
||||||
["schedule_date", ">=", self.course_start_date],
|
["schedule_date", ">=", self.course_start_date],
|
||||||
["schedule_date", "<=", self.course_end_date]])
|
["schedule_date", "<=", self.course_end_date]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
for d in schedules:
|
for d in schedules:
|
||||||
try:
|
try:
|
||||||
if self.day == calendar.day_name[getdate(d.schedule_date).weekday()]:
|
if self.day == calendar.day_name[getdate(d.schedule_date).weekday()]:
|
||||||
@ -98,4 +112,3 @@ class CourseSchedulingTool(Document):
|
|||||||
course_schedule.from_time = self.from_time
|
course_schedule.from_time = self.from_time
|
||||||
course_schedule.to_time = self.to_time
|
course_schedule.to_time = self.to_time
|
||||||
return course_schedule
|
return course_schedule
|
||||||
|
|
Loading…
Reference in New Issue
Block a user