mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 20:29:09 +00:00
Merge branch 'develop' of https://github.com/frappe/erpnext into rebrand-ui
This commit is contained in:
@@ -7,7 +7,7 @@ import frappe
|
||||
import json
|
||||
from frappe import _
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
from frappe.utils import flt, cstr
|
||||
from frappe.utils import flt, cstr, getdate
|
||||
from frappe.email.doctype.email_group.email_group import add_subscribers
|
||||
|
||||
def get_course(program):
|
||||
@@ -67,6 +67,13 @@ def mark_attendance(students_present, students_absent, course_schedule=None, stu
|
||||
:param date: Date.
|
||||
"""
|
||||
|
||||
if student_group:
|
||||
academic_year = frappe.db.get_value('Student Group', student_group, 'academic_year')
|
||||
if academic_year:
|
||||
year_start_date, year_end_date = frappe.db.get_value('Academic Year', academic_year, ['year_start_date', 'year_end_date'])
|
||||
if getdate(date) < getdate(year_start_date) or getdate(date) > getdate(year_end_date):
|
||||
frappe.throw(_('Attendance cannot be marked outside of Academic Year {0}').format(academic_year))
|
||||
|
||||
present = json.loads(students_present)
|
||||
absent = json.loads(students_absent)
|
||||
|
||||
|
||||
@@ -30,6 +30,23 @@ frappe.ui.form.on('Assessment Plan', {
|
||||
frappe.set_route('Form', 'Assessment Result Tool');
|
||||
}, __('Tools'));
|
||||
}
|
||||
|
||||
frm.set_query('course', function() {
|
||||
return {
|
||||
query: 'erpnext.education.doctype.program_enrollment.program_enrollment.get_program_courses',
|
||||
filters: {
|
||||
'program': frm.doc.program
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query('academic_term', function() {
|
||||
return {
|
||||
filters: {
|
||||
'academic_year': frm.doc.academic_year
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
course: function(frm) {
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
"assessment_group",
|
||||
"grading_scale",
|
||||
"column_break_2",
|
||||
"course",
|
||||
"program",
|
||||
"course",
|
||||
"academic_year",
|
||||
"academic_term",
|
||||
"section_break_5",
|
||||
@@ -198,7 +198,7 @@
|
||||
],
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2020-05-09 14:56:26.746988",
|
||||
"modified": "2020-10-23 15:55:35.076251",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Education",
|
||||
"name": "Assessment Plan",
|
||||
|
||||
@@ -7,6 +7,23 @@ frappe.ui.form.on('Assessment Result', {
|
||||
frm.trigger('setup_chart');
|
||||
}
|
||||
frm.set_df_property('details', 'read_only', 1);
|
||||
|
||||
frm.set_query('course', function() {
|
||||
return {
|
||||
query: 'erpnext.education.doctype.program_enrollment.program_enrollment.get_program_courses',
|
||||
filters: {
|
||||
'program': frm.doc.program
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query('academic_term', function() {
|
||||
return {
|
||||
filters: {
|
||||
'academic_year': frm.doc.academic_year
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
onload: function(frm) {
|
||||
|
||||
@@ -41,5 +41,24 @@ frappe.ui.form.on("Instructor", {
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query("academic_term", "instructor_log", function(_doc, cdt, cdn) {
|
||||
let d = locals[cdt][cdn];
|
||||
return {
|
||||
filters: {
|
||||
"academic_year": d.academic_year
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query("course", "instructor_log", function(_doc, cdt, cdn) {
|
||||
let d = locals[cdt][cdn];
|
||||
return {
|
||||
query: "erpnext.education.doctype.program_enrollment.program_enrollment.get_program_courses",
|
||||
filters: {
|
||||
"program": d.program
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1,336 +1,88 @@
|
||||
{
|
||||
"allow_copy": 0,
|
||||
"allow_events_in_timeline": 0,
|
||||
"allow_guest_to_view": 0,
|
||||
"allow_import": 0,
|
||||
"allow_rename": 0,
|
||||
"beta": 0,
|
||||
"creation": "2017-12-27 08:55:52.680284",
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"document_type": "",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"actions": [],
|
||||
"creation": "2017-12-27 08:55:52.680284",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"academic_year",
|
||||
"academic_term",
|
||||
"department",
|
||||
"column_break_3",
|
||||
"program",
|
||||
"course",
|
||||
"student_group",
|
||||
"section_break_8",
|
||||
"other_details"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "academic_year",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Academic Year",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Academic Year",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "academic_year",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Academic Year",
|
||||
"options": "Academic Year",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "academic_term",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Academic Term",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Academic Term",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "academic_term",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Academic Term",
|
||||
"options": "Academic Term"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "department",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Department",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Department",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "department",
|
||||
"fieldtype": "Link",
|
||||
"label": "Department",
|
||||
"options": "Department"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
"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,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "program",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Program",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Program",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "program",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Program",
|
||||
"options": "Program",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Course",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Course",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Course",
|
||||
"options": "Course"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "student_group",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"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 Group",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Student Group",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "student_group",
|
||||
"fieldtype": "Link",
|
||||
"label": "Student Group",
|
||||
"options": "Student Group"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "section_break_8",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
"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,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "section_break_8",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "other_details",
|
||||
"fieldtype": "Small Text",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Other details",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
"fieldname": "other_details",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Other details"
|
||||
}
|
||||
],
|
||||
"has_web_view": 0,
|
||||
"hide_heading": 0,
|
||||
"hide_toolbar": 0,
|
||||
"idx": 0,
|
||||
"image_view": 0,
|
||||
"in_create": 0,
|
||||
"is_submittable": 0,
|
||||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"max_attachments": 0,
|
||||
"modified": "2018-11-04 03:38:30.902942",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Education",
|
||||
"name": "Instructor Log",
|
||||
"name_case": "",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"quick_entry": 1,
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0,
|
||||
"restrict_to_domain": "Education",
|
||||
"show_name_in_global_search": 0,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1,
|
||||
"track_seen": 0,
|
||||
"track_views": 0
|
||||
],
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2020-10-23 15:15:50.759657",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Education",
|
||||
"name": "Instructor Log",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"quick_entry": 1,
|
||||
"restrict_to_domain": "Education",
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -6,17 +6,20 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from frappe import _
|
||||
from frappe.utils import get_link_to_form
|
||||
from frappe.utils import get_link_to_form, getdate, formatdate
|
||||
from erpnext import get_default_company
|
||||
from erpnext.education.api import get_student_group_students
|
||||
|
||||
from erpnext.hr.doctype.holiday_list.holiday_list import is_holiday
|
||||
|
||||
class StudentAttendance(Document):
|
||||
def validate(self):
|
||||
self.validate_mandatory()
|
||||
self.validate_date()
|
||||
self.set_date()
|
||||
self.set_student_group()
|
||||
self.validate_student()
|
||||
self.validate_duplication()
|
||||
self.validate_is_holiday()
|
||||
|
||||
def set_date(self):
|
||||
if self.course_schedule:
|
||||
@@ -27,6 +30,18 @@ class StudentAttendance(Document):
|
||||
frappe.throw(_('{0} or {1} is mandatory').format(frappe.bold('Student Group'),
|
||||
frappe.bold('Course Schedule')), title=_('Mandatory Fields'))
|
||||
|
||||
def validate_date(self):
|
||||
if not self.leave_application and getdate(self.date) > getdate():
|
||||
frappe.throw(_('Attendance cannot be marked for future dates.'))
|
||||
|
||||
if self.student_group:
|
||||
academic_year = frappe.db.get_value('Student Group', self.student_group, 'academic_year')
|
||||
if academic_year:
|
||||
year_start_date, year_end_date = frappe.db.get_value('Academic Year', academic_year, ['year_start_date', 'year_end_date'])
|
||||
if year_start_date and year_end_date:
|
||||
if getdate(self.date) < getdate(year_start_date) or getdate(self.date) > getdate(year_end_date):
|
||||
frappe.throw(_('Attendance cannot be marked outside of Academic Year {0}').format(academic_year))
|
||||
|
||||
def set_student_group(self):
|
||||
if self.course_schedule:
|
||||
self.student_group = frappe.db.get_value('Course Schedule', self.course_schedule, 'student_group')
|
||||
@@ -63,6 +78,21 @@ class StudentAttendance(Document):
|
||||
})
|
||||
|
||||
if attendance_record:
|
||||
record = get_link_to_form('Attendance Record', attendance_record)
|
||||
record = get_link_to_form('Student Attendance', attendance_record)
|
||||
frappe.throw(_('Student Attendance record {0} already exists against the Student {1}')
|
||||
.format(record, frappe.bold(self.student)), title=_('Duplicate Entry'))
|
||||
|
||||
def validate_is_holiday(self):
|
||||
holiday_list = get_holiday_list()
|
||||
if is_holiday(holiday_list, self.date):
|
||||
frappe.throw(_('Attendance cannot be marked for {0} as it is a holiday.').format(
|
||||
frappe.bold(formatdate(self.date))))
|
||||
|
||||
def get_holiday_list(company=None):
|
||||
if not company:
|
||||
company = get_default_company() or frappe.get_all('Company')[0].name
|
||||
|
||||
holiday_list = frappe.get_cached_value('Company', company, 'default_holiday_list')
|
||||
if not holiday_list:
|
||||
frappe.throw(_('Please set a default Holiday List for Company {0}').format(frappe.bold(get_default_company())))
|
||||
return holiday_list
|
||||
|
||||
@@ -52,6 +52,8 @@ frappe.ui.form.on('Student Attendance Tool', {
|
||||
},
|
||||
|
||||
date: function(frm) {
|
||||
if (frm.doc.date > frappe.datetime.get_today())
|
||||
frappe.throw(__("Cannot mark attendance for future dates."));
|
||||
frm.trigger("student_group");
|
||||
},
|
||||
|
||||
@@ -133,8 +135,8 @@ education.StudentsEditor = Class.extend({
|
||||
return !stud.disabled && !stud.checked;
|
||||
});
|
||||
|
||||
frappe.confirm(__("Do you want to update attendance?<br>Present: {0}\
|
||||
<br>Absent: {1}", [students_present.length, students_absent.length]),
|
||||
frappe.confirm(__("Do you want to update attendance? <br> Present: {0} <br> Absent: {1}",
|
||||
[students_present.length, students_absent.length]),
|
||||
function() { //ifyes
|
||||
if(!frappe.request.ajax_count) {
|
||||
frappe.call({
|
||||
|
||||
@@ -1,333 +1,118 @@
|
||||
{
|
||||
"allow_copy": 1,
|
||||
"allow_guest_to_view": 0,
|
||||
"allow_import": 0,
|
||||
"allow_rename": 0,
|
||||
"beta": 0,
|
||||
"creation": "2016-11-16 17:12:46.437539",
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"document_type": "",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"actions": [],
|
||||
"allow_copy": 1,
|
||||
"creation": "2016-11-16 17:12:46.437539",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"based_on",
|
||||
"group_based_on",
|
||||
"column_break_2",
|
||||
"student_group",
|
||||
"academic_year",
|
||||
"academic_term",
|
||||
"course_schedule",
|
||||
"date",
|
||||
"attendance",
|
||||
"students_html"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "",
|
||||
"fieldname": "based_on",
|
||||
"fieldtype": "Select",
|
||||
"hidden": 0,
|
||||
"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",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Student Group\nCourse Schedule",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "based_on",
|
||||
"fieldtype": "Select",
|
||||
"label": "Based On",
|
||||
"options": "Student Group\nCourse Schedule"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "Batch",
|
||||
"depends_on": "eval:doc.based_on == \"Student Group\"",
|
||||
"fieldname": "group_based_on",
|
||||
"fieldtype": "Select",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Group Based On",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Batch\nCourse\nActivity",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"default": "Batch",
|
||||
"depends_on": "eval:doc.based_on == \"Student Group\"",
|
||||
"fieldname": "group_based_on",
|
||||
"fieldtype": "Select",
|
||||
"label": "Group Based On",
|
||||
"options": "Batch\nCourse\nActivity"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "column_break_2",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
"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,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "column_break_2",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "eval:doc.based_on ==\"Student Group\"",
|
||||
"fieldname": "student_group",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Student Group",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Student Group",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"depends_on": "eval:doc.based_on ==\"Student Group\"",
|
||||
"fieldname": "student_group",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Student Group",
|
||||
"options": "Student Group",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "eval:doc.based_on ==\"Course Schedule\"",
|
||||
"fieldname": "course_schedule",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Course Schedule",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Course Schedule",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"depends_on": "eval:doc.based_on ==\"Course Schedule\"",
|
||||
"fieldname": "course_schedule",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Course Schedule",
|
||||
"options": "Course Schedule",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "eval:doc.based_on ==\"Student Group\"",
|
||||
"fieldname": "date",
|
||||
"fieldtype": "Date",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Date",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"depends_on": "eval:doc.based_on ==\"Student Group\"",
|
||||
"fieldname": "date",
|
||||
"fieldtype": "Date",
|
||||
"in_list_view": 1,
|
||||
"label": "Date",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"depends_on": "eval: (doc.course_schedule \n|| (doc.student_group && doc.date))",
|
||||
"fieldname": "attendance",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
"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",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"depends_on": "eval: (doc.course_schedule \n|| (doc.student_group && doc.date))",
|
||||
"fieldname": "attendance",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Attendance"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "students_html",
|
||||
"fieldtype": "HTML",
|
||||
"hidden": 0,
|
||||
"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",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
"fieldname": "students_html",
|
||||
"fieldtype": "HTML",
|
||||
"label": "Students HTML"
|
||||
},
|
||||
{
|
||||
"fetch_from": "student_group.academic_year",
|
||||
"fieldname": "academic_year",
|
||||
"fieldtype": "Link",
|
||||
"label": "Academic Year",
|
||||
"options": "Academic Year",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fetch_from": "student_group.academic_term",
|
||||
"fieldname": "academic_term",
|
||||
"fieldtype": "Link",
|
||||
"label": "Academic Term",
|
||||
"options": "Academic Term",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"has_web_view": 0,
|
||||
"hide_heading": 1,
|
||||
"hide_toolbar": 1,
|
||||
"idx": 0,
|
||||
"image_view": 0,
|
||||
"in_create": 0,
|
||||
"is_submittable": 0,
|
||||
"issingle": 1,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2017-11-10 18:55:36.168044",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Education",
|
||||
"name": "Student Attendance Tool",
|
||||
"name_case": "",
|
||||
"owner": "Administrator",
|
||||
],
|
||||
"hide_toolbar": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2020-10-23 17:52:28.078971",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Education",
|
||||
"name": "Student Attendance Tool",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"amend": 0,
|
||||
"apply_user_permissions": 0,
|
||||
"cancel": 0,
|
||||
"create": 1,
|
||||
"delete": 0,
|
||||
"email": 0,
|
||||
"export": 0,
|
||||
"if_owner": 0,
|
||||
"import": 0,
|
||||
"permlevel": 0,
|
||||
"print": 0,
|
||||
"read": 1,
|
||||
"report": 0,
|
||||
"role": "Instructor",
|
||||
"set_user_permissions": 0,
|
||||
"share": 0,
|
||||
"submit": 0,
|
||||
"create": 1,
|
||||
"read": 1,
|
||||
"role": "Instructor",
|
||||
"write": 1
|
||||
},
|
||||
},
|
||||
{
|
||||
"amend": 0,
|
||||
"apply_user_permissions": 0,
|
||||
"cancel": 0,
|
||||
"create": 1,
|
||||
"delete": 0,
|
||||
"email": 0,
|
||||
"export": 0,
|
||||
"if_owner": 0,
|
||||
"import": 0,
|
||||
"permlevel": 0,
|
||||
"print": 0,
|
||||
"read": 1,
|
||||
"report": 0,
|
||||
"role": "Academics User",
|
||||
"set_user_permissions": 0,
|
||||
"share": 0,
|
||||
"submit": 0,
|
||||
"create": 1,
|
||||
"read": 1,
|
||||
"role": "Academics User",
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"quick_entry": 0,
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0,
|
||||
"restrict_to_domain": "Education",
|
||||
"show_name_in_global_search": 0,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 0,
|
||||
"track_seen": 0
|
||||
],
|
||||
"restrict_to_domain": "Education",
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC"
|
||||
}
|
||||
@@ -20,10 +20,10 @@ def get_student_attendance_records(based_on, date=None, student_group=None, cour
|
||||
student_list = frappe.get_list("Student Group Student", fields=["student", "student_name", "group_roll_number"] , \
|
||||
filters={"parent": student_group, "active": 1}, order_by= "group_roll_number")
|
||||
|
||||
if not student_list:
|
||||
student_list = frappe.get_list("Student Group Student", fields=["student", "student_name", "group_roll_number"] ,
|
||||
if not student_list:
|
||||
student_list = frappe.get_list("Student Group Student", fields=["student", "student_name", "group_roll_number"] ,
|
||||
filters={"parent": student_group, "active": 1}, order_by= "group_roll_number")
|
||||
|
||||
|
||||
if course_schedule:
|
||||
student_attendance_list= frappe.db.sql('''select student, status from `tabStudent Attendance` where \
|
||||
course_schedule= %s''', (course_schedule), as_dict=1)
|
||||
@@ -32,7 +32,7 @@ def get_student_attendance_records(based_on, date=None, student_group=None, cour
|
||||
student_group= %s and date= %s and \
|
||||
(course_schedule is Null or course_schedule='')''',
|
||||
(student_group, date), as_dict=1)
|
||||
|
||||
|
||||
for attendance in student_attendance_list:
|
||||
for student in student_list:
|
||||
if student.student == attendance.student:
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"column_break_3",
|
||||
"from_date",
|
||||
"to_date",
|
||||
"total_leave_days",
|
||||
"section_break_5",
|
||||
"attendance_based_on",
|
||||
"student_group",
|
||||
@@ -110,11 +111,17 @@
|
||||
{
|
||||
"fieldname": "column_break_11",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "total_leave_days",
|
||||
"fieldtype": "Float",
|
||||
"label": "Total Leave Days",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2020-07-08 13:22:38.329002",
|
||||
"modified": "2020-09-21 18:10:24.440669",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Education",
|
||||
"name": "Student Leave Application",
|
||||
|
||||
@@ -6,11 +6,14 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe import _
|
||||
from datetime import timedelta
|
||||
from frappe.utils import get_link_to_form, getdate
|
||||
from frappe.utils import get_link_to_form, getdate, date_diff, flt
|
||||
from erpnext.hr.doctype.holiday_list.holiday_list import is_holiday
|
||||
from erpnext.education.doctype.student_attendance.student_attendance import get_holiday_list
|
||||
from frappe.model.document import Document
|
||||
|
||||
class StudentLeaveApplication(Document):
|
||||
def validate(self):
|
||||
self.validate_holiday_list()
|
||||
self.validate_duplicate()
|
||||
self.validate_from_to_dates('from_date', 'to_date')
|
||||
|
||||
@@ -39,10 +42,19 @@ class StudentLeaveApplication(Document):
|
||||
frappe.throw(_('Leave application {0} already exists against the student {1}')
|
||||
.format(link, frappe.bold(self.student)), title=_('Duplicate Entry'))
|
||||
|
||||
def validate_holiday_list(self):
|
||||
holiday_list = get_holiday_list()
|
||||
self.total_leave_days = get_number_of_leave_days(self.from_date, self.to_date, holiday_list)
|
||||
|
||||
def update_attendance(self):
|
||||
holiday_list = get_holiday_list()
|
||||
|
||||
for dt in daterange(getdate(self.from_date), getdate(self.to_date)):
|
||||
date = dt.strftime('%Y-%m-%d')
|
||||
|
||||
if is_holiday(holiday_list, date):
|
||||
continue
|
||||
|
||||
attendance = frappe.db.exists('Student Attendance', {
|
||||
'student': self.student,
|
||||
'date': date,
|
||||
@@ -89,3 +101,19 @@ class StudentLeaveApplication(Document):
|
||||
def daterange(start_date, end_date):
|
||||
for n in range(int ((end_date - start_date).days)+1):
|
||||
yield start_date + timedelta(n)
|
||||
|
||||
def get_number_of_leave_days(from_date, to_date, holiday_list):
|
||||
number_of_days = date_diff(to_date, from_date) + 1
|
||||
|
||||
holidays = frappe.db.sql("""
|
||||
SELECT
|
||||
COUNT(DISTINCT holiday_date)
|
||||
FROM `tabHoliday` h1,`tabHoliday List` h2
|
||||
WHERE
|
||||
h1.parent = h2.name and
|
||||
h1.holiday_date between %s and %s and
|
||||
h2.name = %s""", (from_date, to_date, holiday_list))[0][0]
|
||||
|
||||
number_of_days = flt(number_of_days) - flt(holidays)
|
||||
|
||||
return number_of_days
|
||||
|
||||
@@ -5,13 +5,15 @@ from __future__ import unicode_literals
|
||||
|
||||
import frappe
|
||||
import unittest
|
||||
from frappe.utils import getdate, add_days
|
||||
from frappe.utils import getdate, add_days, add_months
|
||||
from erpnext import get_default_company
|
||||
from erpnext.education.doctype.student_group.test_student_group import get_random_group
|
||||
from erpnext.education.doctype.student.test_student import create_student
|
||||
|
||||
class TestStudentLeaveApplication(unittest.TestCase):
|
||||
def setUp(self):
|
||||
frappe.db.sql("""delete from `tabStudent Leave Application`""")
|
||||
create_holiday_list()
|
||||
|
||||
def test_attendance_record_creation(self):
|
||||
leave_application = create_leave_application()
|
||||
@@ -35,20 +37,45 @@ class TestStudentLeaveApplication(unittest.TestCase):
|
||||
attendance_status = frappe.db.get_value('Student Attendance', {'leave_application': leave_application.name}, 'docstatus')
|
||||
self.assertTrue(attendance_status, 2)
|
||||
|
||||
def test_holiday(self):
|
||||
today = getdate()
|
||||
leave_application = create_leave_application(from_date=today, to_date= add_days(today, 1), submit=0)
|
||||
|
||||
def create_leave_application(from_date=None, to_date=None, mark_as_present=0):
|
||||
# holiday list validation
|
||||
company = get_default_company() or frappe.get_all('Company')[0].name
|
||||
frappe.db.set_value('Company', company, 'default_holiday_list', '')
|
||||
self.assertRaises(frappe.ValidationError, leave_application.save)
|
||||
|
||||
frappe.db.set_value('Company', company, 'default_holiday_list', 'Test Holiday List for Student')
|
||||
leave_application.save()
|
||||
|
||||
leave_application.reload()
|
||||
self.assertEqual(leave_application.total_leave_days, 1)
|
||||
|
||||
# check no attendance record created for a holiday
|
||||
leave_application.submit()
|
||||
self.assertIsNone(frappe.db.exists('Student Attendance', {'leave_application': leave_application.name, 'date': add_days(today, 1)}))
|
||||
|
||||
def tearDown(self):
|
||||
company = get_default_company() or frappe.get_all('Company')[0].name
|
||||
frappe.db.set_value('Company', company, 'default_holiday_list', '_Test Holiday List')
|
||||
|
||||
|
||||
def create_leave_application(from_date=None, to_date=None, mark_as_present=0, submit=1):
|
||||
student = get_student()
|
||||
|
||||
leave_application = frappe.get_doc({
|
||||
'doctype': 'Student Leave Application',
|
||||
'student': student.name,
|
||||
'attendance_based_on': 'Student Group',
|
||||
'student_group': get_random_group().name,
|
||||
'from_date': from_date if from_date else getdate(),
|
||||
'to_date': from_date if from_date else getdate(),
|
||||
'mark_as_present': mark_as_present
|
||||
}).insert()
|
||||
leave_application.submit()
|
||||
leave_application = frappe.new_doc('Student Leave Application')
|
||||
leave_application.student = student.name
|
||||
leave_application.attendance_based_on = 'Student Group'
|
||||
leave_application.student_group = get_random_group().name
|
||||
leave_application.from_date = from_date if from_date else getdate()
|
||||
leave_application.to_date = from_date if from_date else getdate()
|
||||
leave_application.mark_as_present = mark_as_present
|
||||
|
||||
if submit:
|
||||
leave_application.insert()
|
||||
leave_application.submit()
|
||||
|
||||
return leave_application
|
||||
|
||||
def create_student_attendance(date=None, status=None):
|
||||
@@ -67,4 +94,22 @@ def get_student():
|
||||
email='test_student@gmail.com',
|
||||
first_name='Test',
|
||||
last_name='Student'
|
||||
))
|
||||
))
|
||||
|
||||
def create_holiday_list():
|
||||
holiday_list = 'Test Holiday List for Student'
|
||||
today = getdate()
|
||||
if not frappe.db.exists('Holiday List', holiday_list):
|
||||
frappe.get_doc(dict(
|
||||
doctype = 'Holiday List',
|
||||
holiday_list_name = holiday_list,
|
||||
from_date = add_months(today, -6),
|
||||
to_date = add_months(today, 6),
|
||||
holidays = [
|
||||
dict(holiday_date=add_days(today, 1), description = 'Test')
|
||||
]
|
||||
)).insert()
|
||||
|
||||
company = get_default_company() or frappe.get_all('Company')[0].name
|
||||
frappe.db.set_value('Company', company, 'default_holiday_list', holiday_list)
|
||||
return holiday_list
|
||||
@@ -3,8 +3,10 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.utils import cstr, cint, getdate
|
||||
from frappe.utils import formatdate
|
||||
from frappe import msgprint, _
|
||||
from erpnext.education.doctype.student_attendance.student_attendance import get_holiday_list
|
||||
from erpnext.hr.doctype.holiday_list.holiday_list import is_holiday
|
||||
|
||||
def execute(filters=None):
|
||||
if not filters: filters = {}
|
||||
@@ -15,6 +17,11 @@ def execute(filters=None):
|
||||
columns = get_columns(filters)
|
||||
date = filters.get("date")
|
||||
|
||||
holiday_list = get_holiday_list()
|
||||
if is_holiday(holiday_list, filters.get("date")):
|
||||
msgprint(_("No attendance has been marked for {0} as it is a Holiday").format(frappe.bold(formatdate(filters.get("date")))))
|
||||
|
||||
|
||||
absent_students = get_absent_students(date)
|
||||
leave_applicants = get_leave_applications(date)
|
||||
if absent_students:
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.utils import cstr, cint, getdate
|
||||
from frappe.utils import formatdate
|
||||
from frappe import msgprint, _
|
||||
from erpnext.education.doctype.student_attendance.student_attendance import get_holiday_list
|
||||
from erpnext.hr.doctype.holiday_list.holiday_list import is_holiday
|
||||
|
||||
def execute(filters=None):
|
||||
if not filters: filters = {}
|
||||
@@ -12,6 +14,10 @@ def execute(filters=None):
|
||||
if not filters.get("date"):
|
||||
msgprint(_("Please select date"), raise_exception=1)
|
||||
|
||||
holiday_list = get_holiday_list()
|
||||
if is_holiday(holiday_list, filters.get("date")):
|
||||
msgprint(_("No attendance has been marked for {0} as it is a Holiday").format(frappe.bold(formatdate(filters.get("date")))))
|
||||
|
||||
columns = get_columns(filters)
|
||||
|
||||
active_student_group = get_active_student_group()
|
||||
|
||||
@@ -7,6 +7,8 @@ from frappe.utils import cstr, cint, getdate, get_first_day, get_last_day, date_
|
||||
from frappe import msgprint, _
|
||||
from calendar import monthrange
|
||||
from erpnext.education.api import get_student_group_students
|
||||
from erpnext.education.doctype.student_attendance.student_attendance import get_holiday_list
|
||||
from erpnext.support.doctype.issue.issue import get_holidays
|
||||
|
||||
def execute(filters=None):
|
||||
if not filters: filters = {}
|
||||
@@ -19,26 +21,32 @@ def execute(filters=None):
|
||||
students_list = get_students_list(students)
|
||||
att_map = get_attendance_list(from_date, to_date, filters.get("student_group"), students_list)
|
||||
data = []
|
||||
|
||||
for stud in students:
|
||||
row = [stud.student, stud.student_name]
|
||||
student_status = frappe.db.get_value("Student", stud.student, "enabled")
|
||||
date = from_date
|
||||
total_p = total_a = 0.0
|
||||
|
||||
for day in range(total_days_in_month):
|
||||
status="None"
|
||||
|
||||
if att_map.get(stud.student):
|
||||
status = att_map.get(stud.student).get(date, "None")
|
||||
elif not student_status:
|
||||
status = "Inactive"
|
||||
else:
|
||||
status = "None"
|
||||
status_map = {"Present": "P", "Absent": "A", "None": "", "Inactive":"-"}
|
||||
|
||||
status_map = {"Present": "P", "Absent": "A", "None": "", "Inactive":"-", "Holiday":"H"}
|
||||
row.append(status_map[status])
|
||||
|
||||
if status == "Present":
|
||||
total_p += 1
|
||||
elif status == "Absent":
|
||||
total_a += 1
|
||||
date = add_days(date, 1)
|
||||
|
||||
row += [total_p, total_a]
|
||||
data.append(row)
|
||||
return columns, data
|
||||
@@ -63,14 +71,19 @@ def get_attendance_list(from_date, to_date, student_group, students_list):
|
||||
and date between %s and %s
|
||||
order by student, date''',
|
||||
(student_group, from_date, to_date), as_dict=1)
|
||||
|
||||
att_map = {}
|
||||
students_with_leave_application = get_students_with_leave_application(from_date, to_date, students_list)
|
||||
for d in attendance_list:
|
||||
att_map.setdefault(d.student, frappe._dict()).setdefault(d.date, "")
|
||||
|
||||
if students_with_leave_application.get(d.date) and d.student in students_with_leave_application.get(d.date):
|
||||
att_map[d.student][d.date] = "Present"
|
||||
else:
|
||||
att_map[d.student][d.date] = d.status
|
||||
|
||||
att_map = mark_holidays(att_map, from_date, to_date, students_list)
|
||||
|
||||
return att_map
|
||||
|
||||
def get_students_with_leave_application(from_date, to_date, students_list):
|
||||
@@ -108,3 +121,14 @@ def get_attendance_years():
|
||||
if not year_list:
|
||||
year_list = [getdate().year]
|
||||
return "\n".join(str(year) for year in year_list)
|
||||
|
||||
def mark_holidays(att_map, from_date, to_date, students_list):
|
||||
holiday_list = get_holiday_list()
|
||||
holidays = get_holidays(holiday_list)
|
||||
|
||||
for dt in daterange(getdate(from_date), getdate(to_date)):
|
||||
if dt in holidays:
|
||||
for student in students_list:
|
||||
att_map.setdefault(student, frappe._dict()).setdefault(dt, "Holiday")
|
||||
|
||||
return att_map
|
||||
|
||||
Reference in New Issue
Block a user