Added from date and to date to student leave application
This commit is contained in:
parent
9a7cb6ce92
commit
94f42ea145
@ -103,7 +103,7 @@
|
|||||||
"bold": 0,
|
"bold": 0,
|
||||||
"collapsible": 0,
|
"collapsible": 0,
|
||||||
"columns": 0,
|
"columns": 0,
|
||||||
"fieldname": "date",
|
"fieldname": "from_date",
|
||||||
"fieldtype": "Date",
|
"fieldtype": "Date",
|
||||||
"hidden": 0,
|
"hidden": 0,
|
||||||
"ignore_user_permissions": 0,
|
"ignore_user_permissions": 0,
|
||||||
@ -111,7 +111,7 @@
|
|||||||
"in_filter": 0,
|
"in_filter": 0,
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"in_standard_filter": 1,
|
"in_standard_filter": 1,
|
||||||
"label": "Date",
|
"label": "From Date",
|
||||||
"length": 0,
|
"length": 0,
|
||||||
"no_copy": 0,
|
"no_copy": 0,
|
||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
@ -131,6 +131,35 @@
|
|||||||
"bold": 0,
|
"bold": 0,
|
||||||
"collapsible": 0,
|
"collapsible": 0,
|
||||||
"columns": 0,
|
"columns": 0,
|
||||||
|
"fieldname": "to_date",
|
||||||
|
"fieldtype": "Date",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"ignore_xss_filter": 0,
|
||||||
|
"in_filter": 0,
|
||||||
|
"in_list_view": 1,
|
||||||
|
"in_standard_filter": 0,
|
||||||
|
"label": "To 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
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"columns": 0,
|
||||||
|
"description": "Will show the student as Present in Student Monthly Attendance Report",
|
||||||
"fieldname": "mark_as_present",
|
"fieldname": "mark_as_present",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"hidden": 0,
|
"hidden": 0,
|
||||||
@ -248,7 +277,7 @@
|
|||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 0,
|
"max_attachments": 0,
|
||||||
"modified": "2016-12-20 15:08:40.750278",
|
"modified": "2016-12-21 18:58:00.256114",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Schools",
|
"module": "Schools",
|
||||||
"name": "Student Leave Application",
|
"name": "Student Leave Application",
|
||||||
|
|||||||
@ -55,6 +55,6 @@ def get_absent_students(date):
|
|||||||
def get_leave_applications(date):
|
def get_leave_applications(date):
|
||||||
leave_applicants = []
|
leave_applicants = []
|
||||||
for student in frappe.db.sql("""select student from `tabStudent Leave Application`
|
for student in frappe.db.sql("""select student from `tabStudent Leave Application`
|
||||||
where docstatus = 1 and date = %s""", date):
|
where docstatus = 1 and from_date <= %s and to_date >= %s""", (date, date)):
|
||||||
leave_applicants.append(student[0])
|
leave_applicants.append(student[0])
|
||||||
return leave_applicants
|
return leave_applicants
|
||||||
@ -3,40 +3,40 @@
|
|||||||
|
|
||||||
|
|
||||||
frappe.query_reports["Student Monthly Attendance Sheet"] = {
|
frappe.query_reports["Student Monthly Attendance Sheet"] = {
|
||||||
"filters": [
|
"filters": [{
|
||||||
{
|
"fieldname": "month",
|
||||||
"fieldname":"month",
|
"label": __("Month"),
|
||||||
"label": __("Month"),
|
"fieldtype": "Select",
|
||||||
"fieldtype": "Select",
|
"options": "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec",
|
||||||
"options": "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec",
|
"default": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
|
||||||
"default": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
|
"Dec"
|
||||||
"Dec"][frappe.datetime.str_to_obj(frappe.datetime.get_today()).getMonth()],
|
][frappe.datetime.str_to_obj(frappe.datetime.get_today()).getMonth()],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"year",
|
"fieldname": "year",
|
||||||
"label": __("Year"),
|
"label": __("Year"),
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"student_batch",
|
"fieldname": "student_batch",
|
||||||
"label": __("Student Batch"),
|
"label": __("Student Batch"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Student Batch",
|
"options": "Student Batch",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
"onload": function() {
|
"onload": function() {
|
||||||
return frappe.call({
|
return frappe.call({
|
||||||
method: "erpnext.schools.report.student_monthly_attendance_sheet.student_monthly_attendance_sheet.get_attendance_years",
|
method: "erpnext.schools.report.student_monthly_attendance_sheet.student_monthly_attendance_sheet.get_attendance_years",
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
var year_filter = frappe.query_report_filters_by_name.year;
|
var year_filter = frappe.query_report_filters_by_name.year;
|
||||||
year_filter.df.options = r.message;
|
year_filter.df.options = r.message;
|
||||||
year_filter.df.default = r.message.split("\n")[0];
|
year_filter.df.default = r.message.split("\n")[0];
|
||||||
year_filter.refresh();
|
year_filter.refresh();
|
||||||
year_filter.set_input(year_filter.df.default);
|
year_filter.set_input(year_filter.df.default);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import cstr, cint, getdate
|
from frappe.utils import cstr, cint, getdate, get_first_day, get_last_day, date_diff, add_days
|
||||||
from frappe import msgprint, _
|
from frappe import msgprint, _
|
||||||
from calendar import monthrange
|
from calendar import monthrange
|
||||||
from erpnext.schools.api import get_student_batch_students
|
from erpnext.schools.api import get_student_batch_students
|
||||||
@ -11,86 +11,69 @@ from erpnext.schools.api import get_student_batch_students
|
|||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters: filters = {}
|
if not filters: filters = {}
|
||||||
|
|
||||||
conditions, filters = get_conditions(filters)
|
from_date = get_first_day(filters["month"] + '-' + filters["year"])
|
||||||
columns = get_columns(filters)
|
to_date = get_last_day(filters["month"] + '-' + filters["year"])
|
||||||
att_map = get_attendance_list(conditions, filters)
|
total_days_in_month = date_diff(to_date, from_date) +1
|
||||||
|
columns = get_columns(total_days_in_month)
|
||||||
|
att_map = get_attendance_list(from_date, to_date, filters.get("student_batch"))
|
||||||
students = get_student_batch_students(filters.get("student_batch"))
|
students = get_student_batch_students(filters.get("student_batch"))
|
||||||
data = []
|
data = []
|
||||||
for stud in students:
|
for stud in students:
|
||||||
row = [stud.student, stud.student_name]
|
row = [stud.student, stud.student_name]
|
||||||
|
date = from_date
|
||||||
total_p = total_a = 0.0
|
total_p = total_a = 0.0
|
||||||
for day in range(filters["total_days_in_month"]):
|
for day in range(total_days_in_month):
|
||||||
status="None"
|
status="None"
|
||||||
if att_map.get(stud.student):
|
if att_map.get(stud.student):
|
||||||
status = att_map.get(stud.student).get(day + 1, "None")
|
status = att_map.get(stud.student).get(date, "None")
|
||||||
status_map = {"Present": "P", "Absent": "A", "None": ""}
|
status_map = {"Present": "P", "Absent": "A", "None": ""}
|
||||||
row.append(status_map[status])
|
row.append(status_map[status])
|
||||||
|
|
||||||
if status == "Present":
|
if status == "Present":
|
||||||
total_p += 1
|
total_p += 1
|
||||||
elif status == "Absent":
|
elif status == "Absent":
|
||||||
total_a += 1
|
total_a += 1
|
||||||
|
date = add_days(date, 1)
|
||||||
row += [total_p, total_a]
|
row += [total_p, total_a]
|
||||||
data.append(row)
|
data.append(row)
|
||||||
|
|
||||||
return columns, data
|
return columns, data
|
||||||
|
|
||||||
def get_columns(filters):
|
def get_columns(days_in_month):
|
||||||
columns = [ _("Student") + ":Link/Student:90", _("Student Name") + "::150"]
|
columns = [ _("Student") + ":Link/Student:90", _("Student Name") + "::150"]
|
||||||
|
for day in range(days_in_month):
|
||||||
for day in range(filters["total_days_in_month"]):
|
|
||||||
columns.append(cstr(day+1) +"::20")
|
columns.append(cstr(day+1) +"::20")
|
||||||
|
|
||||||
columns += [_("Total Present") + ":Int:95", _("Total Absent") + ":Int:90"]
|
columns += [_("Total Present") + ":Int:95", _("Total Absent") + ":Int:90"]
|
||||||
return columns
|
return columns
|
||||||
|
|
||||||
def get_attendance_list(conditions, filters):
|
def get_attendance_list(from_date, to_date, student_batch):
|
||||||
attendance_list = frappe.db.sql("""select student, day(date) as day_of_month,
|
attendance_list = frappe.db.sql("""select student, date, status
|
||||||
status from `tabStudent Attendance` where docstatus = 1 %s order by student, date""" %
|
from `tabStudent Attendance` where docstatus = 1 and student_batch = %s
|
||||||
conditions, filters, as_dict=1)
|
and date between %s and %s
|
||||||
|
order by student, date""",
|
||||||
students_with_leave_application = get_students_with_leave_application(filters)
|
(student_batch, from_date, to_date), as_dict=1)
|
||||||
|
|
||||||
att_map = {}
|
att_map = {}
|
||||||
for d in attendance_list:
|
for d in attendance_list:
|
||||||
att_map.setdefault(d.student, frappe._dict()).setdefault(d.day_of_month, "")
|
att_map.setdefault(d.student, frappe._dict()).setdefault(d.date, "")
|
||||||
for stud in students_with_leave_application:
|
students_with_leave_application = get_students_with_leave_application(d.date)
|
||||||
if stud.student== d.student and stud.day_of_month== d.day_of_month:
|
if students_with_leave_application:
|
||||||
att_map[d.student][d.day_of_month] = "Present"
|
for stud in students_with_leave_application:
|
||||||
break
|
if stud.student== d.student:
|
||||||
else:
|
att_map[d.student][d.date] = "Present"
|
||||||
att_map[d.student][d.day_of_month] = d.status
|
break
|
||||||
|
else:
|
||||||
|
att_map[d.student][d.date] = d.status
|
||||||
|
else:
|
||||||
|
att_map[d.student][d.date] = d.status
|
||||||
return att_map
|
return att_map
|
||||||
|
|
||||||
def get_students_with_leave_application(filters):
|
def get_students_with_leave_application(date):
|
||||||
students_with_leave_application = frappe.db.sql("""select student, day(date) as day_of_month
|
students_with_leave_application = frappe.db.sql("""select student from
|
||||||
from `tabStudent Leave Application` where mark_as_present and docstatus = 1
|
`tabStudent Leave Application` where mark_as_present and docstatus = 1 and
|
||||||
and month(date) = %(month)s and year(date) = %(year)s
|
%s between from_date and to_date""", date, as_dict=1)
|
||||||
order by student, date""", filters, as_dict=1)
|
|
||||||
return students_with_leave_application
|
return students_with_leave_application
|
||||||
|
|
||||||
def get_conditions(filters):
|
|
||||||
if not (filters.get("month") and filters.get("year")):
|
|
||||||
msgprint(_("Please select month and year"), raise_exception=1)
|
|
||||||
|
|
||||||
filters["month"] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
|
|
||||||
"Dec"].index(filters.month) + 1
|
|
||||||
|
|
||||||
filters["total_days_in_month"] = monthrange(cint(filters.year), filters.month)[1]
|
|
||||||
|
|
||||||
conditions = " and month(date) = %(month)s and year(date) = %(year)s"
|
|
||||||
|
|
||||||
if filters.get("student_batch"): conditions += " and student_batch = %(student_batch)s"
|
|
||||||
|
|
||||||
return conditions, filters
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_attendance_years():
|
def get_attendance_years():
|
||||||
year_list = frappe.db.sql_list("""select distinct YEAR(date) from `tabStudent Attendance` ORDER BY YEAR(date) DESC""")
|
year_list = frappe.db.sql_list("""select distinct YEAR(date) from `tabStudent Attendance` ORDER BY YEAR(date) DESC""")
|
||||||
if not year_list:
|
if not year_list:
|
||||||
year_list = [getdate().year]
|
year_list = [getdate().year]
|
||||||
|
|
||||||
return "\n".join(str(year) for year in year_list)
|
return "\n".join(str(year) for year in year_list)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user