new employee_leave_balance_report

This commit is contained in:
Rushabh Mehta
2013-02-22 17:54:50 +05:30
parent ff20067a6f
commit 90098d2ebd
23 changed files with 166 additions and 231 deletions

0
hr/report/__init__.py Normal file
View File

View 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

View 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"
}
]