Fixed Student Attendence

This commit is contained in:
Manas Solanki 2017-02-21 11:34:30 +05:30
parent 293158db6e
commit f869a679ae
9 changed files with 172 additions and 141 deletions

View File

@ -375,3 +375,4 @@ erpnext.patches.v7_2.setup_auto_close_settings
erpnext.patches.v7_2.empty_supplied_items_for_non_subcontracted
erpnext.patches.v7_2.arrear_leave_encashment_as_salary_component
erpnext.patches.v7_2.rename_att_date_attendance
erpnext.patches.v7_2.update_attendance_docstatus

View File

@ -0,0 +1,10 @@
import frappe
def execute():
frappe.reload_doctype('Student Attendance')
# frappe.reload_doc("schools", "doctype", "student_attendance")
frappe.db.sql('''
update `tabStudent Attendance` set
docstatus=0
where
docstatus=1''')

View File

@ -1,5 +1,5 @@
<div class="col-sm-3">
<div class="checkbox {% if status %} text-muted {% endif %}">
<div class="checkbox">
<label>
<input
type="checkbox"
@ -7,9 +7,6 @@
data-student="{{student}}"
data-student-name="{{student_name}}"
class="students-check"
{% if status %}
disabled="true"
{% endif %}
{% if status === "Present" %}
checked
{% endif %}

View File

@ -67,21 +67,31 @@ def mark_attendance(students_present, students_absent, course_schedule=None, stu
frappe.msgprint(_("Attendance has been marked successfully."))
def make_attendance_records(student, student_name, status, course_schedule=None, student_batch=None, date=None):
"""Creates Attendance Record.
"""Creates/Update Attendance Record.
:param student: Student.
:param student_name: Student Name.
:param course_schedule: Course Schedule.
:param status: Status (Present/Absent)
"""
student_attendance = frappe.new_doc("Student Attendance")
student_attendance_list = frappe.get_list("Student Attendance", fields = ["name"], filters = {
"student": student,
"course_schedule": course_schedule,
"student_batch": student_batch,
"date": date
})
if student_attendance_list:
student_attendance = frappe.get_doc("Student Attendance", student_attendance_list[0])
else:
student_attendance = frappe.new_doc("Student Attendance")
student_attendance.student = student
student_attendance.student_name = student_name
student_attendance.course_schedule = course_schedule
student_attendance.student_batch = student_batch
student_attendance.date = date
student_attendance.status = status
student_attendance.submit()
student_attendance.save()
@frappe.whitelist()
def get_student_guardians(student):

View File

@ -578,6 +578,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "INDIAN",
"fieldname": "nationality",
"fieldtype": "Data",
"hidden": 0,
@ -1022,7 +1023,7 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
"modified": "2017-02-20 13:20:10.117987",
"modified": "2017-02-21 01:14:59.352772",
"modified_by": "Administrator",
"module": "Schools",
"name": "Student Applicant",
@ -1053,7 +1054,7 @@
"quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
"show_name_in_global_search": 1,
"show_name_in_global_search": 1,
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "title",

View File

@ -170,7 +170,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 1,
"in_global_search": 1,
"in_list_view": 0,
"in_standard_filter": 1,
"label": "Student Batch",
@ -256,11 +256,11 @@
"image_view": 0,
"in_create": 0,
"in_dialog": 0,
"is_submittable": 1,
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2017-02-20 13:19:02.708904",
"modified": "2017-02-21 01:15:20.989687",
"modified_by": "Administrator",
"module": "Schools",
"name": "Student Attendance",
@ -268,9 +268,9 @@
"owner": "Administrator",
"permissions": [
{
"amend": 1,
"amend": 0,
"apply_user_permissions": 0,
"cancel": 1,
"cancel": 0,
"create": 1,
"delete": 1,
"email": 1,
@ -284,7 +284,7 @@
"role": "Academics User",
"set_user_permissions": 0,
"share": 1,
"submit": 1,
"submit": 0,
"write": 1
}
],

View File

@ -3,148 +3,152 @@
frappe.provide("schools")
frappe.ui.form.on('Student Attendance Tool', {
refresh: function(frm) {
frm.disable_save();
},
refresh: function(frm) {
frm.disable_save();
},
based_on: function(frm) {
if (frm.doc.based_on == "Student Batch") {
frm.set_value("course_schedule", "");
} else {
frm.set_value("student_batch", "");
}
},
based_on: function(frm) {
if (frm.doc.based_on == "Student Batch") {
frm.set_value("course_schedule", "");
} else {
frm.set_value("student_batch", "");
}
},
student_batch: function(frm) {
if ((frm.doc.student_batch && frm.doc.date) || frm.doc.course_schedule) {
var method = "erpnext.schools.doctype.student_attendance_tool.student_attendance_tool.get_student_attendance_records";
student_batch: function(frm) {
if ((frm.doc.student_batch && frm.doc.date) || frm.doc.course_schedule) {
var method = "erpnext.schools.doctype.student_attendance_tool.student_attendance_tool.get_student_attendance_records";
frappe.call({
method: method,
args: {
based_on: frm.doc.based_on,
student_batch: frm.doc.student_batch,
date: frm.doc.date,
course_schedule: frm.doc.course_schedule
},
callback: function(r) {
frm.events.get_students(frm, r.message);
}
})
}
},
frappe.call({
method: method,
args: {
based_on: frm.doc.based_on,
student_batch: frm.doc.student_batch,
date: frm.doc.date,
course_schedule: frm.doc.course_schedule
},
callback: function(r) {
frm.events.get_students(frm, r.message);
}
})
}
},
date: function(frm) {
frm.trigger("student_batch");
},
date: function(frm) {
frm.trigger("student_batch");
},
course_schedule: function(frm) {
frm.trigger("student_batch");
},
course_schedule: function(frm) {
frm.trigger("student_batch");
},
get_students: function(frm, students) {
if (!frm.students_area) {
frm.students_area = $('<div>')
.appendTo(frm.fields_dict.students_html.wrapper);
}
frm.students_editor = new schools.StudentsEditor(frm, frm.students_area, students)
}
get_students: function(frm, students) {
if (!frm.students_area) {
frm.students_area = $('<div>')
.appendTo(frm.fields_dict.students_html.wrapper);
}
frm.students_editor = new schools.StudentsEditor(frm, frm.students_area, students)
}
});
schools.StudentsEditor = Class.extend({
init: function(frm, wrapper, students) {
this.wrapper = wrapper;
this.frm = frm;
this.make(frm, students);
},
make: function(frm, students) {
var me = this;
init: function(frm, wrapper, students) {
this.wrapper = wrapper;
this.frm = frm;
this.make(frm, students);
},
make: function(frm, students) {
var me = this;
$(this.wrapper).empty();
var student_toolbar = $('<p>\
$(this.wrapper).empty();
var student_toolbar = $('<p>\
<button class="btn btn-default btn-add btn-xs" style="margin-right: 5px;"></button>\
<button class="btn btn-xs btn-default btn-remove" style="margin-right: 5px;"></button>\
<button class="btn btn-default btn-primary btn-mark-att btn-xs"></button></p>').appendTo($(this.wrapper));
student_toolbar.find(".btn-add")
.html(__('Check all'))
.on("click", function() {
$(me.wrapper).find('input[type="checkbox"]').each(function(i, check) {
if (!$(check).prop("disabled")) {
check.checked = true;
}
});
});
student_toolbar.find(".btn-add")
.html(__('Check all'))
.on("click", function() {
$(me.wrapper).find('input[type="checkbox"]').each(function(i, check) {
if (!$(check).prop("disabled")) {
check.checked = true;
}
});
});
student_toolbar.find(".btn-remove")
.html(__('Uncheck all'))
.on("click", function() {
$(me.wrapper).find('input[type="checkbox"]').each(function(i, check) {
if (!$(check).prop("disabled")) {
check.checked = false;
}
});
});
student_toolbar.find(".btn-remove")
.html(__('Uncheck all'))
.on("click", function() {
$(me.wrapper).find('input[type="checkbox"]').each(function(i, check) {
if (!$(check).prop("disabled")) {
check.checked = false;
}
});
});
var get_present_student = function(student) {
return students.filter(function(s) {
return s.idx === idx;
})
}
var get_absent_student = function(idx) {
return students.filter(function(s) {
return s.idx === idx;
})
}
var get_present_student = function(student) {
return students.filter(function(s) {
return s.idx === idx;
})
}
var get_absent_student = function(idx) {
return students.filter(function(s) {
return s.idx === idx;
})
}
student_toolbar.find(".btn-mark-att")
.html(__('Mark Attendence'))
.on("click", function() {
var studs = [];
$(me.wrapper.find('input[type="checkbox"]')).each(function(i, check) {
var $check = $(check);
studs.push({
student: $check.data().student,
student_name: $check.data().studentName,
idx: $check.data().idx,
disabled: $check.prop("disabled"),
checked: $check.is(":checked")
});
});
student_toolbar.find(".btn-mark-att")
.html(__('Mark Attendence'))
.on("click", function() {
var studs = [];
$(me.wrapper.find('input[type="checkbox"]')).each(function(i, check) {
var $check = $(check);
studs.push({
student: $check.data().student,
student_name: $check.data().studentName,
idx: $check.data().idx,
disabled: $check.prop("disabled"),
checked: $check.is(":checked")
});
});
var students_present = studs.filter(function(stud) {
return !stud.disabled && stud.checked;
});
var students_present = studs.filter(function(stud) {
return !stud.disabled && stud.checked;
});
var students_absent = studs.filter(function(stud) {
return !stud.disabled && !stud.checked;
});
var students_absent = studs.filter(function(stud) {
return !stud.disabled && !stud.checked;
});
frappe.call({
method: "erpnext.schools.api.mark_attendance",
args: {
"students_present": students_present,
"students_absent": students_absent,
"student_batch": frm.doc.student_batch,
"course_schedule": frm.doc.course_schedule,
"date": frm.doc.date
},
callback: function(r) {
frm.trigger("student_batch");
}
});
});
frappe.confirm(__("Do you want to save attendance?<br>Present: {0}\
<br>Absent: {1}", [students_present.length, students_absent.length]), function() {
frappe.call({
method: "erpnext.schools.api.mark_attendance",
args: {
"students_present": students_present,
"students_absent": students_absent,
"student_batch": frm.doc.student_batch,
"course_schedule": frm.doc.course_schedule,
"date": frm.doc.date
},
callback: function(r) {
frm.trigger("student_batch");
}
});
});
var htmls = students.map(function(student) {
return frappe.render_template("student_button", {
student: student.student,
student_name: student.student_name,
idx: student.idx,
status: student.status
})
});
});
$(htmls.join("")).appendTo(me.wrapper);
}
var htmls = students.map(function(student) {
return frappe.render_template("student_button", {
student: student.student,
student_name: student.student_name,
idx: student.idx,
status: student.status
})
});
$(htmls.join("")).appendTo(me.wrapper);
}
});

View File

@ -23,6 +23,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Based On",
@ -52,6 +53,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"length": 0,
@ -80,6 +82,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Student Batch",
@ -110,6 +113,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Course Schedule",
@ -140,6 +144,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Date",
@ -169,6 +174,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Attendance",
@ -197,6 +203,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Students HTML",
@ -225,7 +232,7 @@
"issingle": 1,
"istable": 0,
"max_attachments": 0,
"modified": "2016-12-09 17:36:28.739318",
"modified": "2017-02-21 01:15:11.435110",
"modified_by": "Administrator",
"module": "Schools",
"name": "Student Attendance Tool",
@ -242,7 +249,6 @@
"export": 0,
"if_owner": 0,
"import": 0,
"is_custom": 0,
"permlevel": 0,
"print": 0,
"read": 1,
@ -263,7 +269,6 @@
"export": 0,
"if_owner": 0,
"import": 0,
"is_custom": 0,
"permlevel": 0,
"print": 1,
"read": 1,
@ -278,7 +283,9 @@
"quick_entry": 0,
"read_only": 0,
"read_only_onload": 0,
"show_name_in_global_search": 0,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 0,
"track_seen": 0
}

View File

@ -27,10 +27,10 @@ def get_student_attendance_records(based_on, date=None, student_batch=None, cour
if course_schedule:
student_attendance_list= frappe.db.sql("""select student, status from `tabStudent Attendance` where \
course_schedule= %s and docstatus=1""", (course_schedule), as_dict=1)
course_schedule= %s""", (course_schedule), as_dict=1)
else:
student_attendance_list= frappe.db.sql("""select student, status from `tabStudent Attendance` where \
student_batch= %s and date= %s and docstatus=1 and \
student_batch= %s and date= %s and \
(course_schedule is Null or course_schedule='')""",
(student_batch, date), as_dict=1)
@ -38,4 +38,5 @@ def get_student_attendance_records(based_on, date=None, student_batch=None, cour
for student in student_list:
if student.student == attendance.student:
student.status = attendance.status
print student_list
return student_list