mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-31 10:49:09 +00:00
fix: Calendar events for leaves considering user permissions
This commit is contained in:
@@ -487,7 +487,6 @@ def get_events(start, end, filters=None):
|
|||||||
|
|
||||||
add_block_dates(events, start, end, employee, company)
|
add_block_dates(events, start, end, employee, company)
|
||||||
add_holidays(events, start, end, employee, company)
|
add_holidays(events, start, end, employee, company)
|
||||||
|
|
||||||
return events
|
return events
|
||||||
|
|
||||||
def add_department_leaves(events, start, end, employee, company):
|
def add_department_leaves(events, start, end, employee, company):
|
||||||
@@ -500,10 +499,22 @@ def add_department_leaves(events, start, end, employee, company):
|
|||||||
department_employees = frappe.db.sql_list("""select name from tabEmployee where department=%s
|
department_employees = frappe.db.sql_list("""select name from tabEmployee where department=%s
|
||||||
and company=%s""", (department, company))
|
and company=%s""", (department, company))
|
||||||
|
|
||||||
match_conditions = "and employee in (\"%s\")" % '", "'.join(department_employees)
|
filter_conditions = "employee in (\"%s\")" % '", "'.join(department_employees)
|
||||||
add_leaves(events, start, end, match_conditions=match_conditions)
|
add_leaves(events, start, end, filter_conditions=filter_conditions)
|
||||||
|
|
||||||
|
def add_leaves(events, start, end, filter_conditions=None):
|
||||||
|
conditions = []
|
||||||
|
|
||||||
|
if filter_conditions:
|
||||||
|
conditions.append(filter_conditions)
|
||||||
|
|
||||||
|
if not cint(frappe.db.get_value("HR Settings", None, "show_leaves_of_all_department_members_in_calendar")):
|
||||||
|
from frappe.desk.reportview import build_match_conditions
|
||||||
|
match_conditions = build_match_conditions("Leave Application")
|
||||||
|
|
||||||
|
if match_conditions:
|
||||||
|
conditions.append(match_conditions)
|
||||||
|
|
||||||
def add_leaves(events, start, end, match_conditions=None):
|
|
||||||
query = """select name, from_date, to_date, employee_name, half_day,
|
query = """select name, from_date, to_date, employee_name, half_day,
|
||||||
status, employee, docstatus
|
status, employee, docstatus
|
||||||
from `tabLeave Application` where
|
from `tabLeave Application` where
|
||||||
@@ -511,8 +522,8 @@ def add_leaves(events, start, end, match_conditions=None):
|
|||||||
and docstatus < 2
|
and docstatus < 2
|
||||||
and status!="Rejected" """
|
and status!="Rejected" """
|
||||||
|
|
||||||
if match_conditions:
|
if conditions:
|
||||||
query += match_conditions
|
query += ' and ' + ' and '.join(conditions)
|
||||||
|
|
||||||
for d in frappe.db.sql(query, {"start":start, "end": end}, as_dict=True):
|
for d in frappe.db.sql(query, {"start":start, "end": end}, as_dict=True):
|
||||||
e = {
|
e = {
|
||||||
|
|||||||
Reference in New Issue
Block a user