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:
parent
dae8f1b353
commit
5e7b2eb338
@ -8,6 +8,7 @@ from frappe.utils import getdate, nowdate
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from erpnext.hr.utils import set_employee_name
|
from erpnext.hr.utils import set_employee_name
|
||||||
|
from frappe.utils import cstr
|
||||||
|
|
||||||
class Attendance(Document):
|
class Attendance(Document):
|
||||||
def validate_duplicate_record(self):
|
def validate_duplicate_record(self):
|
||||||
@ -54,3 +55,36 @@ class Attendance(Document):
|
|||||||
self.validate_attendance_date()
|
self.validate_attendance_date()
|
||||||
self.validate_duplicate_record()
|
self.validate_duplicate_record()
|
||||||
self.check_leave_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)
|
18
erpnext/hr/doctype/attendance/attendance_calendar.js
Normal file
18
erpnext/hr/doctype/attendance/attendance_calendar.js
Normal 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"
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user