Add Calendar View to Attendance doctype (#13919)

* [fix] #13917

* codacy fixes

* remove company

* add status

* fix date issue

* code optimizations

* change sql
This commit is contained in:
Pawan Mehta 2018-05-04 18:12:35 +05:30 committed by Nabin Hait
parent dae8f1b353
commit 5e7b2eb338
2 changed files with 52 additions and 0 deletions

View File

@ -8,6 +8,7 @@ from frappe.utils import getdate, nowdate
from frappe import _
from frappe.model.document import Document
from erpnext.hr.utils import set_employee_name
from frappe.utils import cstr
class Attendance(Document):
def validate_duplicate_record(self):
@ -54,3 +55,36 @@ class Attendance(Document):
self.validate_attendance_date()
self.validate_duplicate_record()
self.check_leave_record()
@frappe.whitelist()
def get_events(start, end, filters=None):
events = []
employee = frappe.db.get_value("Employee", {"user_id": frappe.session.user})
if not employee:
return events
from frappe.desk.reportview import get_filters_cond
conditions = get_filters_cond("Attendance", filters, [])
add_attendance(events, start, end, conditions=conditions)
return events
def add_attendance(events, start, end, conditions=None):
query = """select name, attendance_date, status
from `tabAttendance` where
attendance_date between %(from_date)s and %(to_date)s
and docstatus < 2"""
if conditions:
query += conditions
for d in frappe.db.sql(query, {"from_date":start, "to_date":end}, as_dict=True):
e = {
"name": d.name,
"doctype": "Attendance",
"date": d.attendance_date,
"title": cstr(d.status),
"docstatus": d.docstatus
}
if e not in events:
events.append(e)

View File

@ -0,0 +1,18 @@
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.views.calendar["Attendance"] = {
field_map: {
"start": "date",
"end": "date",
"id": "name",
"docstatus": 1
},
options: {
header: {
left: 'prev,next today',
center: 'title',
right: 'month'
}
},
get_events_method: "erpnext.hr.doctype.attendance.attendance.get_events"
};