fix: class schedule date and time validation
This commit is contained in:
@@ -21,13 +21,10 @@ frappe.ui.form.on("LMS Class", {
|
||||
},
|
||||
callback: (r) => {
|
||||
if (r.message) {
|
||||
let date = frappe.datetime.get_today();
|
||||
r.message.forEach((lesson) => {
|
||||
let row = frm.add_child("scheduled_flow");
|
||||
row.lesson = lesson.name;
|
||||
row.lesson_title = lesson.title;
|
||||
row.date = date;
|
||||
date = frappe.datetime.add_days(date, 1);
|
||||
});
|
||||
frm.refresh_field("scheduled_flow");
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
"start_date",
|
||||
"end_date",
|
||||
"column_break_4",
|
||||
"end_time",
|
||||
"start_time",
|
||||
"end_time",
|
||||
"section_break_rgfj",
|
||||
"medium",
|
||||
"category",
|
||||
@@ -24,13 +24,13 @@
|
||||
"description",
|
||||
"students",
|
||||
"courses",
|
||||
"section_break_lbwu",
|
||||
"fetch_lessons",
|
||||
"scheduled_flow",
|
||||
"section_break_ubxi",
|
||||
"custom_component",
|
||||
"assessment_tab",
|
||||
"assessment"
|
||||
"assessment",
|
||||
"schedule_tab",
|
||||
"fetch_lessons",
|
||||
"scheduled_flow"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -139,10 +139,6 @@
|
||||
"fieldtype": "Autocomplete",
|
||||
"label": "Category"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_lbwu",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "scheduled_flow",
|
||||
"fieldtype": "Table",
|
||||
@@ -157,11 +153,16 @@
|
||||
"fieldname": "fetch_lessons",
|
||||
"fieldtype": "Button",
|
||||
"label": "Fetch Lessons"
|
||||
},
|
||||
{
|
||||
"fieldname": "schedule_tab",
|
||||
"fieldtype": "Tab Break",
|
||||
"label": "Schedule"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2023-07-31 15:45:03.839896",
|
||||
"modified": "2023-08-10 12:54:44.351907",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Class",
|
||||
|
||||
@@ -19,6 +19,7 @@ class LMSClass(Document):
|
||||
self.validate_duplicate_students()
|
||||
self.validate_duplicate_assessments()
|
||||
self.validate_membership()
|
||||
self.validate_schedule()
|
||||
|
||||
def validate_duplicate_students(self):
|
||||
students = [row.student for row in self.students]
|
||||
@@ -67,6 +68,35 @@ class LMSClass(Document):
|
||||
if cint(self.seat_count) < len(self.students):
|
||||
frappe.throw(_("There are no seats available in this class."))
|
||||
|
||||
def validate_schedule(self):
|
||||
for schedule in self.scheduled_flow:
|
||||
if schedule.start_time and schedule.end_time:
|
||||
if (
|
||||
schedule.start_time > schedule.end_time or schedule.start_time == schedule.end_time
|
||||
):
|
||||
frappe.throw(
|
||||
_("Row #{0} Start time cannot be greater than or equal to end time.").format(
|
||||
schedule.idx
|
||||
)
|
||||
)
|
||||
|
||||
if schedule.start_time < self.start_time or schedule.start_time > self.end_time:
|
||||
frappe.throw(
|
||||
_("Row #{0} Start time cannot be outside the class duration.").format(
|
||||
schedule.idx
|
||||
)
|
||||
)
|
||||
|
||||
if schedule.end_time < self.start_time or schedule.end_time > self.end_time:
|
||||
frappe.throw(
|
||||
_("Row #{0} End time cannot be outside the class duration.").format(schedule.idx)
|
||||
)
|
||||
|
||||
if schedule.date < self.start_date or schedule.date > self.end_date:
|
||||
frappe.throw(
|
||||
_("Row #{0} Date cannot be outside the class duration.").format(schedule.idx)
|
||||
)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def remove_student(student, class_name):
|
||||
|
||||
@@ -571,7 +571,7 @@
|
||||
|
||||
{{ lesson.title }}
|
||||
|
||||
{% if get_membership(lesson.course, current_student.name) %}
|
||||
{% if current_student.name and get_membership(lesson.course, current_student.name) %}
|
||||
{% set lesson_progress = get_progress(lesson.course, lesson.name, current_student.name) %}
|
||||
<svg class="icon icon-md lesson-progress-tick ml-3 {% if lesson_progress != 'Complete' %} hide {% endif %}">
|
||||
<use class="" href="#icon-success">
|
||||
|
||||
Reference in New Issue
Block a user