mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-22 06:29:20 +00:00
new employee_leave_balance_report
This commit is contained in:
0
hr/report/__init__.py
Normal file
0
hr/report/__init__.py
Normal file
0
hr/report/employee_leave_balance/__init__.py
Normal file
0
hr/report/employee_leave_balance/__init__.py
Normal file
46
hr/report/employee_leave_balance/employee_leave_balance.py
Normal file
46
hr/report/employee_leave_balance/employee_leave_balance.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes.widgets.reportview import execute as runreport
|
||||
|
||||
def execute():
|
||||
employees = runreport(doctype="Employee", fields=["name", "employee_name", "department"])
|
||||
leave_types = webnotes.conn.sql_list("select name from `tabLeave Type`")
|
||||
fiscal_years = webnotes.conn.sql_list("select name from `tabFiscal Year` order by name desc")
|
||||
employee_in = '", "'.join([e.name for e in employees])
|
||||
|
||||
allocations = webnotes.conn.sql("""select employee, fiscal_year, leave_type, total_leaves_allocated
|
||||
from `tabLeave Allocation`
|
||||
where docstatus=1 and employee in ("%s")""" % employee_in, as_dict=True)
|
||||
applications = webnotes.conn.sql("""select employee, fiscal_year, leave_type, SUM(total_leave_days) as leaves
|
||||
from `tabLeave Application`
|
||||
where status="Approved" and docstatus = 1 and employee in ("%s")
|
||||
group by employee, fiscal_year, leave_type""" % employee_in, as_dict=True)
|
||||
|
||||
columns = [
|
||||
"Fiscal Year", "Employee:Link/Employee:150", "Employee Name::200", "Department::150"
|
||||
]
|
||||
|
||||
for leave_type in leave_types:
|
||||
columns.append(leave_type + " Allocated:Float")
|
||||
columns.append(leave_type + " Taken:Float")
|
||||
|
||||
data = {}
|
||||
for d in allocations:
|
||||
data.setdefault((d.fiscal_year, d.employee,
|
||||
d.leave_type), webnotes._dict()).allocation = d.total_leaves_allocated
|
||||
|
||||
for d in applications:
|
||||
data.setdefault((d.fiscal_year, d.employee,
|
||||
d.leave_type), webnotes._dict()).leaves = d.leaves
|
||||
|
||||
result = []
|
||||
for fiscal_year in fiscal_years:
|
||||
for employee in employees:
|
||||
row = [fiscal_year, employee.name, employee.employee_name, employee.department]
|
||||
result.append(row)
|
||||
for leave_type in leave_types:
|
||||
tmp = data.get((fiscal_year, employee.name, leave_type), webnotes._dict())
|
||||
row.append(tmp.allocation or 0)
|
||||
row.append(tmp.leaves or 0)
|
||||
|
||||
return columns, result
|
||||
21
hr/report/employee_leave_balance/employee_leave_balance.txt
Normal file
21
hr/report/employee_leave_balance/employee_leave_balance.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-02-22 15:29:34",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-02-22 15:53:01",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
{
|
||||
"doctype": "Report",
|
||||
"is_standard": "Yes",
|
||||
"name": "__common__",
|
||||
"ref_doctype": "Employee",
|
||||
"report_name": "Employee Leave Balance",
|
||||
"report_type": "Script Report"
|
||||
},
|
||||
{
|
||||
"doctype": "Report",
|
||||
"name": "Employee Leave Balance"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user