add department filter to employee leave balance
This commit is contained in:
parent
8f47bffa0e
commit
7cc6a67c18
@ -411,7 +411,8 @@ def get_leave_details(employee, date):
|
||||
leave_allocation = {}
|
||||
for d in allocation_records:
|
||||
allocation = allocation_records.get(d, frappe._dict())
|
||||
remaining_leaves = get_leave_balance_on(employee, d, date)
|
||||
remaining_leaves = get_leave_balance_on(employee, d, date, to_date = allocation.to_date,
|
||||
consider_all_leaves_in_the_allocation_period=True)
|
||||
date = allocation.to_date
|
||||
leaves_taken = get_leaves_for_period(employee, d, allocation.from_date, date, status="Approved")
|
||||
leaves_pending = get_leaves_for_period(employee, d, allocation.from_date, date, status="Open")
|
||||
@ -441,6 +442,7 @@ def get_leave_balance_on(employee, leave_type, from_date, to_date=nowdate(), all
|
||||
expiry = get_allocation_expiry(employee, leave_type, to_date, from_date)
|
||||
|
||||
leaves_taken = get_leaves_taken(employee, leave_type, allocation.from_date, end_date)
|
||||
|
||||
return get_remaining_leaves(allocation, leaves_taken, from_date, expiry)
|
||||
|
||||
def get_remaining_leaves(allocation, leaves_taken, date, expiry):
|
||||
|
@ -65,21 +65,21 @@
|
||||
{
|
||||
"fieldname": "from_date",
|
||||
"fieldtype": "Date",
|
||||
"in_list_view": 1,
|
||||
"label": "From Date"
|
||||
},
|
||||
{
|
||||
"fieldname": "to_date",
|
||||
"fieldtype": "Date",
|
||||
"in_list_view": 1,
|
||||
"label": "To Date"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "is_carry_forward",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is Carry Forward"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "is_expired",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is Expired"
|
||||
@ -87,7 +87,7 @@
|
||||
],
|
||||
"in_create": 1,
|
||||
"is_submittable": 1,
|
||||
"modified": "2019-05-27 03:25:47.805142",
|
||||
"modified": "2019-05-29 15:58:29.656351",
|
||||
"modified_by": "Administrator",
|
||||
"module": "HR",
|
||||
"name": "Leave Ledger Entry",
|
||||
|
@ -24,6 +24,13 @@ frappe.query_reports["Employee Leave Balance"] = {
|
||||
"options": "Company",
|
||||
"reqd": 1,
|
||||
"default": frappe.defaults.get_user_default("Company")
|
||||
},
|
||||
{
|
||||
"fieldname":"department",
|
||||
"label": __("Department"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Department",
|
||||
"reqd": 1,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import flt
|
||||
from erpnext.hr.doctype.leave_application.leave_application \
|
||||
import get_leave_allocation_records, get_leave_balance_on, get_approved_leaves_for_period, get_total_allocated_leaves
|
||||
|
||||
@ -30,14 +31,23 @@ def get_columns(leave_types):
|
||||
|
||||
return columns
|
||||
|
||||
def get_conditions(filters):
|
||||
filters = {
|
||||
"status": "Active",
|
||||
"company": filters.company,
|
||||
}
|
||||
if filters.get("Department"):
|
||||
filters.update(filters.get("Department"))
|
||||
|
||||
return filters
|
||||
|
||||
def get_data(filters, leave_types):
|
||||
user = frappe.session.user
|
||||
allocation_records_based_on_to_date = get_leave_allocation_records(filters.to_date)
|
||||
allocation_records_based_on_from_date = get_leave_allocation_records(filters.from_date)
|
||||
conditions = get_conditions(filters)
|
||||
|
||||
active_employees = frappe.get_all("Employee",
|
||||
filters = { "status": "Active", "company": filters.company},
|
||||
fields = ["name", "employee_name", "department", "user_id"])
|
||||
filters=conditions,
|
||||
fields=["name", "employee_name", "department", "user_id"])
|
||||
|
||||
data = []
|
||||
for employee in active_employees:
|
||||
@ -54,8 +64,7 @@ def get_data(filters, leave_types):
|
||||
opening = get_total_allocated_leaves(employee.name, leave_type, filters.to_date)
|
||||
|
||||
# closing balance
|
||||
closing = get_leave_balance_on(employee.name, leave_type, filters.to_date,
|
||||
allocation_records_based_on_to_date.get(employee.name, frappe._dict()))
|
||||
closing = flt(opening) - flt(leaves_taken)
|
||||
|
||||
row += [opening, leaves_taken, closing]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user