Merge pull request #7193 from KanchanChauhan/get-project-task
Show only Project tasks in depends on tasks
diff --git a/erpnext/accounts/doctype/budget/budget.js b/erpnext/accounts/doctype/budget/budget.js
index 40e929a..6697b17 100644
--- a/erpnext/accounts/doctype/budget/budget.js
+++ b/erpnext/accounts/doctype/budget/budget.js
@@ -36,5 +36,18 @@
}
}
})
+ },
+
+ refresh: function(frm) {
+ frm.trigger("toggle_reqd_fields")
+ },
+
+ budget_against: function(frm) {
+ frm.trigger("toggle_reqd_fields")
+ },
+
+ toggle_reqd_fields: function(frm) {
+ frm.toggle_reqd("cost_center", frm.doc.budget_against=="Cost Center");
+ frm.toggle_reqd("project", frm.doc.budget_against=="Project");
}
});
diff --git a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js
index 8cfbc83..2b7f1f3 100644
--- a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js
+++ b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js
@@ -31,6 +31,14 @@
options: "Company",
default: frappe.defaults.get_user_default("Company"),
reqd: 1
+ },
+ {
+ fieldname: "budget_against",
+ label: __("Budget Against"),
+ fieldtype: "Select",
+ options: ["Cost Center", "Project"],
+ default: "Cost Center",
+ reqd: 1
}
]
}
diff --git a/erpnext/accounts/report/budget_variance_report/budget_variance_report.py b/erpnext/accounts/report/budget_variance_report/budget_variance_report.py
index 0be0b3d..875ec99 100644
--- a/erpnext/accounts/report/budget_variance_report/budget_variance_report.py
+++ b/erpnext/accounts/report/budget_variance_report/budget_variance_report.py
@@ -12,7 +12,7 @@
if not filters: filters = {}
columns = get_columns(filters)
- cost_centers = get_cost_centers(filters.company)
+ cost_centers = get_cost_centers(filters)
period_month_ranges = get_period_month_ranges(filters["period"], filters["fiscal_year"])
cam_map = get_cost_center_account_month_map(filters)
@@ -40,7 +40,7 @@
return columns, data
def get_columns(filters):
- columns = [_("Cost Center") + ":Link/Cost Center:120", _("Account") + ":Link/Account:120"]
+ columns = [_(filters.get("budget_against")) + ":Link/%s:120"%(filters.get("budget_against")), _("Account") + ":Link/Account:120"]
group_months = False if filters["period"] == "Monthly" else True
@@ -56,16 +56,23 @@
return columns + [_("Total Target") + ":Float:120", _("Total Actual") + ":Float:120",
_("Total Variance") + ":Float:120"]
-def get_cost_centers(company):
- return frappe.db.sql_list("select name from `tabCost Center` where company=%s order by lft", company)
+def get_cost_centers(filters):
+ cond = "and 1=1"
+ if filters.get("budget_against") == "Cost Center":
+ cond = "order by lft"
+
+ return frappe.db.sql_list("""select name from `tab{tab}` where company=%s
+ {cond}""".format(tab=filters.get("budget_against"), cond=cond), filters.get("company"))
#Get cost center & target details
def get_cost_center_target_details(filters):
return frappe.db.sql("""
- select b.cost_center, b.monthly_distribution, ba.account, ba.budget_amount
+ select b.{budget_against} as budget_against, b.monthly_distribution, ba.account, ba.budget_amount
from `tabBudget` b, `tabBudget Account` ba
- where b.name=ba.parent and b.docstatus = 1 and b.fiscal_year=%s and b.company=%s
- """, (filters.fiscal_year, filters.company), as_dict=True)
+ where b.name=ba.parent and b.docstatus = 1 and b.fiscal_year=%s
+ and b.budget_against = %s and b.company=%s
+ """.format(budget_against=filters.get("budget_against").replace(" ", "_").lower()),
+ (filters.fiscal_year, filters.budget_against, filters.company), as_dict=True)
#Get target distribution details of accounts of cost center
def get_target_distribution_details(filters):
@@ -78,20 +85,26 @@
return target_details
#Get actual details from gl entry
-def get_actual_details(cost_center, fiscal_year):
- cc_lft, cc_rgt = frappe.db.get_value("Cost Center", cost_center, ["lft", "rgt"])
+def get_actual_details(name, filters):
+ cond = "1=1"
+ budget_against=filters.get("budget_against").replace(" ", "_").lower()
+
+ if filters.get("budget_against") == "Cost Center":
+ cc_lft, cc_rgt = frappe.db.get_value("Cost Center", name, ["lft", "rgt"])
+ cond = "lft>='{lft}' and rgt<='{rgt}'".format(lft = cc_lft, rgt=cc_rgt)
ac_details = frappe.db.sql("""select gl.account, gl.debit, gl.credit,
- MONTHNAME(gl.posting_date) as month_name, b.cost_center
+ MONTHNAME(gl.posting_date) as month_name, b.{budget_against} as budget_against
from `tabGL Entry` gl, `tabBudget Account` ba, `tabBudget` b
where
b.name = ba.parent
and b.docstatus = 1
and ba.account=gl.account
and gl.fiscal_year=%s
- and b.cost_center=%s
- and exists(select name from `tabCost Center` where name=gl.cost_center and lft>=%s and rgt<=%s)
- """, (fiscal_year, cost_center, cc_lft, cc_rgt), as_dict=1)
+ and b.{budget_against}=%s
+ and exists(select name from `tab{tab}` where name=gl.{budget_against} and {cond})
+ """.format(tab = filters.budget_against, budget_against = budget_against, cond = cond),
+ (filters.fiscal_year, name), as_dict=1)
cc_actual_details = {}
for d in ac_details:
@@ -107,17 +120,17 @@
cam_map = {}
for ccd in cost_center_target_details:
- actual_details = get_actual_details(ccd.cost_center, filters.fiscal_year)
+ actual_details = get_actual_details(ccd.budget_against, filters)
for month_id in range(1, 13):
month = datetime.date(2013, month_id, 1).strftime('%B')
- cam_map.setdefault(ccd.cost_center, {}).setdefault(ccd.account, {})\
+ cam_map.setdefault(ccd.budget_against, {}).setdefault(ccd.account, {})\
.setdefault(month, frappe._dict({
"target": 0.0, "actual": 0.0
}))
- tav_dict = cam_map[ccd.cost_center][ccd.account][month]
+ tav_dict = cam_map[ccd.budget_against][ccd.account][month]
month_percentage = tdd.get(ccd.monthly_distribution, {}).get(month, 0) \
if ccd.monthly_distribution else 100.0/12
diff --git a/erpnext/config/schools.py b/erpnext/config/schools.py
index f9696d0..1d33d4d 100644
--- a/erpnext/config/schools.py
+++ b/erpnext/config/schools.py
@@ -68,7 +68,7 @@
},
{
"type": "doctype",
- "name": "Student Batch Attendance Tool"
+ "name": "Student Attendance Tool"
},
{
"type": "report",
diff --git a/erpnext/public/build.json b/erpnext/public/build.json
index ac1c7c3..30b0900 100644
--- a/erpnext/public/build.json
+++ b/erpnext/public/build.json
@@ -1,37 +1,38 @@
{
- "css/erpnext.css": [
- "public/css/erpnext.css"
- ],
- "js/erpnext-web.min.js": [
- "public/js/website_utils.js",
- "public/js/shopping_cart.js"
- ],
- "js/erpnext.min.js": [
- "public/js/conf.js",
- "public/js/utils.js",
- "public/js/queries.js",
- "public/js/sms_manager.js",
- "public/js/utils/party.js",
- "public/js/templates/address_list.html",
- "public/js/templates/contact_list.html",
- "public/js/controllers/stock_controller.js",
- "public/js/payment/payments.js",
- "public/js/controllers/taxes_and_totals.js",
- "public/js/controllers/transaction.js",
- "public/js/pos/pos.html",
- "public/js/pos/pos_bill_item.html",
- "public/js/pos/pos_item.html",
- "public/js/pos/pos_tax_row.html",
- "public/js/pos/pos_invoice_list.html",
- "public/js/payment/pos_payment.html",
- "public/js/payment/payment_details.html",
- "public/js/templates/item_selector.html",
- "public/js/utils/item_selector.js",
- "public/js/help_links.js"
- ],
- "js/item-dashboard.min.js": [
- "stock/dashboard/item_dashboard.html",
- "stock/dashboard/item_dashboard_list.html",
- "stock/dashboard/item_dashboard.js"
- ]
-}
+ "css/erpnext.css": [
+ "public/css/erpnext.css"
+ ],
+ "js/erpnext-web.min.js": [
+ "public/js/website_utils.js",
+ "public/js/shopping_cart.js"
+ ],
+ "js/erpnext.min.js": [
+ "public/js/conf.js",
+ "public/js/utils.js",
+ "public/js/queries.js",
+ "public/js/sms_manager.js",
+ "public/js/utils/party.js",
+ "public/js/templates/address_list.html",
+ "public/js/templates/contact_list.html",
+ "public/js/controllers/stock_controller.js",
+ "public/js/payment/payments.js",
+ "public/js/controllers/taxes_and_totals.js",
+ "public/js/controllers/transaction.js",
+ "public/js/pos/pos.html",
+ "public/js/pos/pos_bill_item.html",
+ "public/js/pos/pos_item.html",
+ "public/js/pos/pos_tax_row.html",
+ "public/js/pos/pos_invoice_list.html",
+ "public/js/payment/pos_payment.html",
+ "public/js/payment/payment_details.html",
+ "public/js/templates/item_selector.html",
+ "public/js/utils/item_selector.js",
+ "public/js/help_links.js",
+ "public/js/schools/student_button.html"
+ ],
+ "js/item-dashboard.min.js": [
+ "stock/dashboard/item_dashboard.html",
+ "stock/dashboard/item_dashboard_list.html",
+ "stock/dashboard/item_dashboard.js"
+ ]
+}
\ No newline at end of file
diff --git a/erpnext/public/js/schools/student_button.html b/erpnext/public/js/schools/student_button.html
new file mode 100644
index 0000000..dabaf26
--- /dev/null
+++ b/erpnext/public/js/schools/student_button.html
@@ -0,0 +1,20 @@
+<div class="col-sm-3">
+ <div class="checkbox {% if status %} text-muted {% endif %}">
+ <label>
+ <input
+ type="checkbox"
+ data-idx="{{idx}}"
+ data-student="{{student}}"
+ data-student-name="{{student_name}}"
+ class="students-check"
+ {% if status %}
+ disabled="true"
+ {% endif %}
+ {% if status === "Present" %}
+ checked
+ {% endif %}
+ >
+ {{ idx }} - {{ student_name }}
+ </label>
+ </div>
+</div>
\ No newline at end of file
diff --git a/erpnext/schools/api.py b/erpnext/schools/api.py
index 7cb02a3..bf09351 100644
--- a/erpnext/schools/api.py
+++ b/erpnext/schools/api.py
@@ -52,8 +52,10 @@
:param student_batch: Student Batch.
:param date: Date.
"""
+
present = json.loads(students_present)
absent = json.loads(students_absent)
+
for d in present:
make_attendance_records(d["student"], d["student_name"], "Present", course_schedule, student_batch, date)
diff --git a/erpnext/schools/doctype/course_schedule/course_schedule.js b/erpnext/schools/doctype/course_schedule/course_schedule.js
index 04a8cde..12e8522 100644
--- a/erpnext/schools/doctype/course_schedule/course_schedule.js
+++ b/erpnext/schools/doctype/course_schedule/course_schedule.js
@@ -1,134 +1,15 @@
frappe.provide("schools")
frappe.ui.form.on("Course Schedule", {
- onload: function(frm) {
- if (frm.doc.from_datetime && frm.doc.to_datetime) {
- var from_datetime = moment(frm.doc.from_datetime);
- var to_datetime = moment(frm.doc.to_datetime);
- frm.doc.schedule_date = from_datetime.format(moment.defaultFormat);
- frm.doc.from_time = from_datetime.format("HH:mm:ss");
- frm.doc.to_time = to_datetime.format("HH:mm:ss");
- }
- },
-
refresh: function(frm) {
- if (!frm.doc.__islocal && frm.doc.student_group) {
- frappe.call({
- method: "erpnext.schools.api.check_attendance_records_exist",
- args: {
- "course_schedule": frm.doc.name
- },
- callback: function(r) {
- if (r.message) {
- hide_field('attendance');
- frm.events.view_attendance(frm)
- } else {
- frappe.call({
- method: "erpnext.schools.api.get_student_group_students",
- args: {
- "student_group": frm.doc.student_group
- },
- callback: function(r) {
- if (r.message) {
- frm.events.get_students(frm, r.message)
- }
- }
- });
- }
+ if (!frm.doc.__islocal) {
+ frm.add_custom_button(__("Attendance"), function() {
+ frappe.route_options = {
+ based_on: "Course Schedule",
+ course_schedule: frm.doc.name
}
+ frappe.set_route("Form", "Student Attendance Tool");
});
- } else {
- hide_field('attendance');
}
- },
-
- view_attendance: function(frm) {
- hide_field('attendance');
- frm.add_custom_button(__("View attendance"), function() {
- frappe.route_options = {
- course_schedule: frm.doc.name
- }
- frappe.set_route("List", "Student Attendance");
- });
- },
-
- 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;
-
- $(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).is(":checked")) {
- 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).is(":checked")) {
- check.checked = false;
- }
- });
- });
-
- student_toolbar.find(".btn-mark-att")
- .html(__('Mark Attendence'))
- .on("click", function() {
- var students_present = [];
- var students_absent = [];
- $(me.wrapper).find('input[type="checkbox"]').each(function(i, check) {
- if ($(check).is(":checked")) {
- students_present.push(students[i]);
- } else {
- students_absent.push(students[i]);
- }
- });
- frappe.call({
- method: "erpnext.schools.api.mark_attendance",
- args: {
- "students_present": students_present,
- "students_absent": students_absent,
- "course_schedule": frm.doc.name
- },
- callback: function(r) {
- frm.events.view_attendance(frm)
- }
- });
- });
-
-
- $.each(students, function(i, m) {
- $(repl('<div class="col-sm-6">\
- <div class="checkbox">\
- <label><input type="checkbox" class="students-check" student="%(student)s">\
- %(student)s</label>\
- </div></div>', { student: m.student_name })).appendTo(me.wrapper);
- });
- }
-})
\ No newline at end of file
+});
\ No newline at end of file
diff --git a/erpnext/schools/doctype/course_schedule/course_schedule.json b/erpnext/schools/doctype/course_schedule/course_schedule.json
index 122285e..450d7cf 100644
--- a/erpnext/schools/doctype/course_schedule/course_schedule.json
+++ b/erpnext/schools/doctype/course_schedule/course_schedule.json
@@ -385,62 +385,6 @@
{
"allow_on_submit": 0,
"bold": 0,
- "collapsible": 1,
- "columns": 0,
- "fieldname": "attendance",
- "fieldtype": "Section Break",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 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
- },
- {
- "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_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": 1,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "unique": 0
- },
- {
- "allow_on_submit": 0,
- "bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "title",
@@ -478,7 +422,7 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
- "modified": "2016-12-01 12:59:25.086606",
+ "modified": "2016-12-09 17:00:02.822788",
"modified_by": "Administrator",
"module": "Schools",
"name": "Course Schedule",
diff --git a/erpnext/schools/doctype/student_attendance/student_attendance.py b/erpnext/schools/doctype/student_attendance/student_attendance.py
index 45b3014..e2d01b5 100644
--- a/erpnext/schools/doctype/student_attendance/student_attendance.py
+++ b/erpnext/schools/doctype/student_attendance/student_attendance.py
@@ -31,9 +31,9 @@
(self.student, self.course_schedule, self.name))
else:
attendance_records= frappe.db.sql("""select name from `tabStudent Attendance` where \
- student= %s and date= %s and name != %s and docstatus=1 and \
+ student= %s and student_batch= %s and date= %s and name != %s and docstatus=1 and \
(course_schedule is Null or course_schedule='')""",
- (self.student, self.date, self.name))
+ (self.student, self.student_batch, self.date, self.name))
if attendance_records:
frappe.throw(_("Attendance Record {0} exists against Student {1}")
diff --git a/erpnext/schools/doctype/student_batch_attendance_tool/__init__.py b/erpnext/schools/doctype/student_attendance_tool/__init__.py
similarity index 100%
rename from erpnext/schools/doctype/student_batch_attendance_tool/__init__.py
rename to erpnext/schools/doctype/student_attendance_tool/__init__.py
diff --git a/erpnext/schools/doctype/student_attendance_tool/student_attendance_tool.js b/erpnext/schools/doctype/student_attendance_tool/student_attendance_tool.js
new file mode 100644
index 0000000..7dd9dda
--- /dev/null
+++ b/erpnext/schools/doctype/student_attendance_tool/student_attendance_tool.js
@@ -0,0 +1,150 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+frappe.provide("schools")
+
+frappe.ui.form.on('Student Attendance Tool', {
+ 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", "");
+ }
+ },
+
+ 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);
+ }
+ })
+ }
+ },
+
+ date: 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)
+ }
+});
+
+
+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;
+
+ $(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-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;
+ })
+ }
+
+ 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_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");
+ }
+ });
+ });
+
+ 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);
+ }
+});
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student_batch_attendance_tool/student_batch_attendance_tool.json b/erpnext/schools/doctype/student_attendance_tool/student_attendance_tool.json
similarity index 72%
rename from erpnext/schools/doctype/student_batch_attendance_tool/student_batch_attendance_tool.json
rename to erpnext/schools/doctype/student_attendance_tool/student_attendance_tool.json
index defc886..092af04 100644
--- a/erpnext/schools/doctype/student_batch_attendance_tool/student_batch_attendance_tool.json
+++ b/erpnext/schools/doctype/student_attendance_tool/student_attendance_tool.json
@@ -16,18 +16,19 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "fieldname": "student_batch",
- "fieldtype": "Link",
+ "default": "",
+ "fieldname": "based_on",
+ "fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
- "label": "Student Batch",
+ "label": "Based On",
"length": 0,
"no_copy": 0,
- "options": "Student Batch",
+ "options": "Student Batch\nCourse Schedule",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@@ -35,7 +36,7 @@
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
- "reqd": 1,
+ "reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
@@ -72,6 +73,67 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
+ "depends_on": "eval:doc.based_on ==\"Student Batch\"",
+ "fieldname": "student_batch",
+ "fieldtype": "Link",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Student Batch",
+ "length": 0,
+ "no_copy": 0,
+ "options": "Student Batch",
+ "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,
+ "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_list_view": 0,
+ "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
+ },
+ {
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "depends_on": "eval:doc.based_on ==\"Student Batch\"",
"fieldname": "date",
"fieldtype": "Date",
"hidden": 0,
@@ -100,7 +162,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "depends_on": "",
+ "depends_on": "eval: (doc.course_schedule \n|| (doc.student_batch && doc.date))",
"fieldname": "attendance",
"fieldtype": "Section Break",
"hidden": 0,
@@ -163,10 +225,10 @@
"issingle": 1,
"istable": 0,
"max_attachments": 0,
- "modified": "2016-12-01 12:58:31.822014",
+ "modified": "2016-12-09 17:36:28.739318",
"modified_by": "Administrator",
"module": "Schools",
- "name": "Student Batch Attendance Tool",
+ "name": "Student Attendance Tool",
"name_case": "",
"owner": "Administrator",
"permissions": [
diff --git a/erpnext/schools/doctype/student_attendance_tool/student_attendance_tool.py b/erpnext/schools/doctype/student_attendance_tool/student_attendance_tool.py
new file mode 100644
index 0000000..30a692c
--- /dev/null
+++ b/erpnext/schools/doctype/student_attendance_tool/student_attendance_tool.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class StudentAttendanceTool(Document):
+ pass
+
+@frappe.whitelist()
+def get_student_attendance_records(based_on, date=None, student_batch=None, course_schedule=None):
+ student_list = []
+ student_attendance_list = []
+
+ if based_on=="Course Schedule":
+ student_group = frappe.db.get_value("Course Schedule", course_schedule, "student_group")
+ if student_group:
+ student_list = frappe.get_list("Student Group Student", fields=["student", "student_name", "idx"] , \
+ filters={"parent": student_group}, order_by= "idx")
+ else:
+ student_batch = frappe.db.get_value("Course Schedule", course_schedule, "student_batch")
+ if not student_list:
+ student_list = frappe.get_list("Student Batch Student", fields=["student", "student_name", "idx"] , filters={"parent": student_batch}, order_by= "idx")
+
+ 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)
+ else:
+ student_attendance_list= frappe.db.sql("""select student, status from `tabStudent Attendance` where \
+ student_batch= %s and date= %s and docstatus=1 and \
+ (course_schedule is Null or course_schedule='')""",
+ (student_batch, date), as_dict=1)
+
+ for attendance in student_attendance_list:
+ for student in student_list:
+ if student.student == attendance.student:
+ student.status = attendance.status
+ return student_list
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student_batch_attendance_tool/student_batch_attendance_tool.js b/erpnext/schools/doctype/student_batch_attendance_tool/student_batch_attendance_tool.js
deleted file mode 100644
index 2dc6a85..0000000
--- a/erpnext/schools/doctype/student_batch_attendance_tool/student_batch_attendance_tool.js
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
-// For license information, please see license.txt
-frappe.provide("schools")
-
-frappe.ui.form.on('Student Batch Attendance Tool', {
- refresh: function(frm) {
- frm.disable_save();
- hide_field('attendance');
- },
-
- student_batch: function(frm) {
- if (frm.doc.student_batch && frm.doc.date) {
- frappe.call({
- method: "erpnext.schools.api.check_attendance_records_exist",
- args: {
- "student_batch": frm.doc.student_batch,
- "date": frm.doc.date
- },
- callback: function(r) {
- if (r.message) {
- frappe.msgprint("Attendance already marked.");
- hide_field('attendance');
- } else {
- frappe.call({
- method: "erpnext.schools.api.get_student_batch_students",
- args: {
- "student_batch": frm.doc.student_batch
- },
- callback: function(r) {
- if (r.message) {
- unhide_field('attendance');
- frm.events.get_students(frm, r.message)
- }
- }
- });
- }
- }
- });
- }
- },
-
- date: 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)
- }
-});
-
-
-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;
-
- $(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).is(":checked")) {
- 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).is(":checked")) {
- check.checked = false;
- }
- });
- });
-
- var get_student = function(idx) {
- return students.filter(function(s) {
- return s.idx === idx;
- })[0]
- }
-
- student_toolbar.find(".btn-mark-att")
- .html(__('Mark Attendence'))
- .on("click", function() {
- var students_present = [];
- var students_absent = [];
- $(me.wrapper).find('input[type="checkbox"]').each(function(i, check) {
- var idx = $(check).data().idx;
- if ($(check).is(":checked")) {
- students_present.push(get_student(idx));
- } else {
- students_absent.push(get_student(idx));
- }
- });
- frappe.call({
- method: "erpnext.schools.api.mark_attendance",
- args: {
- "students_present": students_present,
- "students_absent": students_absent,
- "student_batch": frm.doc.student_batch,
- "date": frm.doc.date
- },
- callback: function(r) {
- hide_field('attendance');
- }
- });
- });
-
-
- $.each(students, function(i, m) {
- $(repl('<div class="col-sm-6">\
- <div class="checkbox">\
- <label><input data-idx="%(idx)s" type="checkbox" class="students-check" data-student="%(name)s">\
- %(idx)s - %(name)s</label>\
- </div></div>', {
- name: m.student_name,
- idx: m.idx
- })).appendTo(me.wrapper);
- });
- }
-});
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student_batch_attendance_tool/student_batch_attendance_tool.py b/erpnext/schools/doctype/student_batch_attendance_tool/student_batch_attendance_tool.py
deleted file mode 100644
index 49a5ae8..0000000
--- a/erpnext/schools/doctype/student_batch_attendance_tool/student_batch_attendance_tool.py
+++ /dev/null
@@ -1,10 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
-# For license information, please see license.txt
-
-from __future__ import unicode_literals
-import frappe
-from frappe.model.document import Document
-
-class StudentBatchAttendanceTool(Document):
- pass