feat: Init Employee Leave Balance Summary report

This commit is contained in:
Suraj Shetty 2019-09-05 12:42:29 +05:30
parent 0252c1478e
commit 607a21e02a
4 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,36 @@
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
/* eslint-disable */
frappe.query_reports["Employee Leave Balance Summary"] = {
"filters": [
{
"fieldname":"from_date",
"label": __("From Date"),
"fieldtype": "Date",
"reqd": 1,
"default": frappe.defaults.get_default("year_start_date")
},
{
"fieldname":"to_date",
"label": __("To Date"),
"fieldtype": "Date",
"reqd": 1,
"default": frappe.defaults.get_default("year_end_date")
},
{
"fieldname":"company",
"label": __("Company"),
"fieldtype": "Link",
"options": "Company",
"reqd": 1,
"default": frappe.defaults.get_user_default("Company")
},
{
"fieldname":"employee",
"label": __("Employee"),
"fieldtype": "Link",
"options": "Employee",
}
]
};

View File

@ -0,0 +1,34 @@
{
"add_total_row": 0,
"creation": "2019-09-05 11:18:06.209397",
"disable_prepared_report": 0,
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"idx": 0,
"is_standard": "Yes",
"letter_head": "sapcon-old",
"modified": "2019-09-05 11:18:06.209397",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Leave Balance Summary",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Employee",
"report_name": "Employee Leave Balance Summary",
"report_type": "Script Report",
"roles": [
{
"role": "Employee"
},
{
"role": "HR Manager"
},
{
"role": "HR User"
},
{
"role": "Leave Approver"
}
]
}

View File

@ -0,0 +1,63 @@
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe.utils import flt
from frappe import _
from erpnext.hr.doctype.leave_application.leave_application \
import get_leave_balance_on, get_leaves_for_period
from erpnext.hr.report.employee_leave_balance.employee_leave_balance \
import get_total_allocated_leaves
def execute(filters=None):
columns = get_columns()
data = get_data(filters)
return columns, data
def get_columns():
columns = []
columns.append(_('Leave Type') )
columns.append(_('Employee'))
columns.append(_('Employee Name'))
columns.append(_('Opening Balance') + ':Float:160')
columns.append(_('Leaves Taken') + ':Float:160')
columns.append(_('Closing Balance') + ':Float:160')
return columns
def get_data(filters):
leave_types = frappe.db.sql_list("SELECT `name` FROM `tabLeave Type` ORDER BY `name` ASC")
if filters.to_date <= filters.from_date:
frappe.throw(_('From date can not be greater than than To date'))
conditions = {
'status': 'Active',
}
if filters.get('employee'):
conditions['name'] = filters.get('employee')
active_employees = frappe.get_all('Employee',
filters=conditions,
fields=['name', 'employee_name', 'department', 'user_id'])
data = []
for leave_type in leave_types:
for employee in active_employees:
row = [leave_type, employee.name, employee.employee_name]
leaves_taken = get_leaves_for_period(employee.name, leave_type,
filters.from_date, filters.to_date) * -1
opening = get_total_allocated_leaves(employee.name, leave_type, filters.from_date, filters.to_date)
closing = flt(opening) - flt(leaves_taken)
row += [opening, leaves_taken, closing]
data.append(row)
return data