* feat: color and leave type in leave application calendar * fix: sider + use cstring (cherry picked from commit 366eb86fdfd9bb204bce677b01b8d5bb5ffa4d6d) Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
This commit is contained in:
parent
94dcbf851a
commit
e958ae9002
@ -662,26 +662,30 @@ def is_lwp(leave_type):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_events(start, end, filters=None):
|
def get_events(start, end, filters=None):
|
||||||
|
from frappe.desk.reportview import get_filters_cond
|
||||||
events = []
|
events = []
|
||||||
|
|
||||||
employee = frappe.db.get_value("Employee", {"user_id": frappe.session.user}, ["name", "company"],
|
employee = frappe.db.get_value("Employee",
|
||||||
as_dict=True)
|
filters={"user_id": frappe.session.user},
|
||||||
|
fieldname=["name", "company"],
|
||||||
|
as_dict=True
|
||||||
|
)
|
||||||
|
|
||||||
if employee:
|
if employee:
|
||||||
employee, company = employee.name, employee.company
|
employee, company = employee.name, employee.company
|
||||||
else:
|
else:
|
||||||
employee=''
|
employee = ''
|
||||||
company=frappe.db.get_value("Global Defaults", None, "default_company")
|
company = frappe.db.get_value("Global Defaults", None, "default_company")
|
||||||
|
|
||||||
from frappe.desk.reportview import get_filters_cond
|
|
||||||
conditions = get_filters_cond("Leave Application", filters, [])
|
conditions = get_filters_cond("Leave Application", filters, [])
|
||||||
# show department leaves for employee
|
# show department leaves for employee
|
||||||
if "Employee" in frappe.get_roles():
|
if "Employee" in frappe.get_roles():
|
||||||
add_department_leaves(events, start, end, employee, company)
|
add_department_leaves(events, start, end, employee, company)
|
||||||
|
|
||||||
add_leaves(events, start, end, conditions)
|
add_leaves(events, start, end, conditions)
|
||||||
|
|
||||||
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):
|
||||||
@ -697,26 +701,37 @@ def add_department_leaves(events, start, end, employee, company):
|
|||||||
filter_conditions = " and employee in (\"%s\")" % '", "'.join(department_employees)
|
filter_conditions = " and employee in (\"%s\")" % '", "'.join(department_employees)
|
||||||
add_leaves(events, start, end, filter_conditions=filter_conditions)
|
add_leaves(events, start, end, filter_conditions=filter_conditions)
|
||||||
|
|
||||||
|
|
||||||
def add_leaves(events, start, end, filter_conditions=None):
|
def add_leaves(events, start, end, filter_conditions=None):
|
||||||
|
from frappe.desk.reportview import build_match_conditions
|
||||||
conditions = []
|
conditions = []
|
||||||
|
|
||||||
|
|
||||||
if not cint(frappe.db.get_value("HR Settings", None, "show_leaves_of_all_department_members_in_calendar")):
|
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")
|
match_conditions = build_match_conditions("Leave Application")
|
||||||
|
|
||||||
if match_conditions:
|
if match_conditions:
|
||||||
conditions.append(match_conditions)
|
conditions.append(match_conditions)
|
||||||
|
|
||||||
query = """select name, from_date, to_date, employee_name, half_day,
|
query = """SELECT
|
||||||
status, employee, docstatus
|
docstatus,
|
||||||
from `tabLeave Application` where
|
name,
|
||||||
from_date <= %(end)s and to_date >= %(start)s <= to_date
|
employee,
|
||||||
and docstatus < 2
|
employee_name,
|
||||||
and status!='Rejected' """
|
leave_type,
|
||||||
|
from_date,
|
||||||
|
to_date,
|
||||||
|
half_day,
|
||||||
|
status,
|
||||||
|
color
|
||||||
|
FROM `tabLeave Application`
|
||||||
|
WHERE
|
||||||
|
from_date <= %(end)s AND to_date >= %(start)s <= to_date
|
||||||
|
AND docstatus < 2
|
||||||
|
AND status != 'Rejected'
|
||||||
|
"""
|
||||||
|
|
||||||
if conditions:
|
if conditions:
|
||||||
query += ' and ' + ' and '.join(conditions)
|
query += ' AND ' + ' AND '.join(conditions)
|
||||||
|
|
||||||
if filter_conditions:
|
if filter_conditions:
|
||||||
query += filter_conditions
|
query += filter_conditions
|
||||||
@ -729,11 +744,13 @@ def add_leaves(events, start, end, filter_conditions=None):
|
|||||||
"to_date": d.to_date,
|
"to_date": d.to_date,
|
||||||
"docstatus": d.docstatus,
|
"docstatus": d.docstatus,
|
||||||
"color": d.color,
|
"color": d.color,
|
||||||
"title": cstr(d.employee_name) + (' ' + _('(Half Day)') if d.half_day else ''),
|
"all_day": int(not d.half_day),
|
||||||
|
"title": cstr(d.employee_name) + f' ({cstr(d.leave_type)})' + (' ' + _('(Half Day)') if d.half_day else ''),
|
||||||
}
|
}
|
||||||
if e not in events:
|
if e not in events:
|
||||||
events.append(e)
|
events.append(e)
|
||||||
|
|
||||||
|
|
||||||
def add_block_dates(events, start, end, employee, company):
|
def add_block_dates(events, start, end, employee, company):
|
||||||
# block days
|
# block days
|
||||||
from erpnext.hr.doctype.leave_block_list.leave_block_list import get_applicable_block_dates
|
from erpnext.hr.doctype.leave_block_list.leave_block_list import get_applicable_block_dates
|
||||||
|
@ -7,7 +7,9 @@ frappe.views.calendar["Leave Application"] = {
|
|||||||
"end": "to_date",
|
"end": "to_date",
|
||||||
"id": "name",
|
"id": "name",
|
||||||
"title": "title",
|
"title": "title",
|
||||||
"docstatus": 1
|
"docstatus": 1,
|
||||||
|
"color": "color",
|
||||||
|
"allDay": "all_day"
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
header: {
|
header: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user