mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-04 12:49:10 +00:00
[fix] filters for calendars frappe/erpnext#9850 (#9870)
This commit is contained in:
committed by
Makarand Bauskar
parent
e012e24423
commit
660de515b5
@@ -69,27 +69,17 @@ def get_events(start, end, filters=None):
|
||||
:param end: End date-time.
|
||||
:param filters: Filters (JSON).
|
||||
"""
|
||||
condition = ''
|
||||
values = {
|
||||
"start_date": getdate(start),
|
||||
"end_date": getdate(end)
|
||||
}
|
||||
|
||||
if filters:
|
||||
if isinstance(filters, basestring):
|
||||
filters = json.loads(filters)
|
||||
filters = json.loads(filters)
|
||||
else:
|
||||
filters = []
|
||||
|
||||
if filters.get('holiday_list'):
|
||||
condition = 'and hlist.name=%(holiday_list)s'
|
||||
values['holiday_list'] = filters['holiday_list']
|
||||
if start:
|
||||
filters.append(['Holiday', 'holiday_date', '>', getdate(start)])
|
||||
if end:
|
||||
filters.append(['Holiday', 'holiday_date', '<', getdate(end)])
|
||||
|
||||
data = frappe.db.sql("""select hlist.name, h.holiday_date, h.description
|
||||
from `tabHoliday List` hlist, tabHoliday h
|
||||
where h.parent = hlist.name
|
||||
and h.holiday_date is not null
|
||||
and h.holiday_date >= %(start_date)s
|
||||
and h.holiday_date <= %(end_date)s
|
||||
{condition}""".format(condition=condition),
|
||||
values, as_dict=True, update={"allDay": 1})
|
||||
|
||||
return data
|
||||
return frappe.get_list('Holiday List',
|
||||
fields=['name', '`tabHoliday`.holiday_date', '`tabHoliday`.description'],
|
||||
filters = filters,
|
||||
update={"allDay": 1})
|
||||
|
||||
@@ -400,7 +400,7 @@ def is_lwp(leave_type):
|
||||
return lwp and cint(lwp[0][0]) or 0
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_events(start, end):
|
||||
def get_events(start, end, filters=None):
|
||||
events = []
|
||||
|
||||
employee = frappe.db.get_value("Employee", {"user_id": frappe.session.user}, ["name", "company"],
|
||||
@@ -411,14 +411,14 @@ def get_events(start, end):
|
||||
employee=''
|
||||
company=frappe.db.get_value("Global Defaults", None, "default_company")
|
||||
|
||||
from frappe.desk.reportview import build_match_conditions
|
||||
match_conditions = build_match_conditions("Leave Application")
|
||||
from frappe.desk.reportview import get_filters_cond
|
||||
conditions = get_filters_cond("Leave Application")
|
||||
|
||||
# show department leaves for employee
|
||||
if "Employee" in frappe.get_roles():
|
||||
add_department_leaves(events, start, end, employee, company)
|
||||
|
||||
add_leaves(events, start, end, match_conditions)
|
||||
add_leaves(events, start, end, conditions)
|
||||
|
||||
add_block_dates(events, start, end, employee, company)
|
||||
add_holidays(events, start, end, employee, company)
|
||||
|
||||
@@ -9,9 +9,8 @@ from frappe import _
|
||||
import json
|
||||
from datetime import timedelta
|
||||
from erpnext.controllers.queries import get_match_cond
|
||||
from frappe.utils import flt, time_diff_in_hours, get_datetime, getdate, cint, get_datetime_str
|
||||
from frappe.utils import flt, time_diff_in_hours, get_datetime, getdate, cint
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
from erpnext.manufacturing.doctype.workstation.workstation import (check_if_within_operating_hours,
|
||||
WorkstationHolidayError)
|
||||
from erpnext.manufacturing.doctype.manufacturing_settings.manufacturing_settings import get_mins_between_operations
|
||||
@@ -364,8 +363,9 @@ def get_events(start, end, filters=None):
|
||||
:param filters: Filters (JSON).
|
||||
"""
|
||||
filters = json.loads(filters)
|
||||
from frappe.desk.calendar import get_event_conditions
|
||||
conditions = get_event_conditions("Timesheet", filters)
|
||||
|
||||
conditions = get_conditions(filters)
|
||||
return frappe.db.sql("""select `tabTimesheet Detail`.name as name,
|
||||
`tabTimesheet Detail`.docstatus as status, `tabTimesheet Detail`.parent as parent,
|
||||
from_time as start_date, hours, activity_type,
|
||||
@@ -381,15 +381,3 @@ def get_events(start, end, filters=None):
|
||||
"end": end
|
||||
}, as_dict=True, update={"allDay": 0})
|
||||
|
||||
def get_conditions(filters):
|
||||
conditions = []
|
||||
for key in filters:
|
||||
if filters.get(key):
|
||||
if frappe.get_meta("Timesheet").has_field(key):
|
||||
dt = 'tabTimesheet'
|
||||
elif frappe.get_meta("Timesheet Detail").has_field(key):
|
||||
dt = 'tabTimesheet Detail'
|
||||
|
||||
conditions.append("`%s`.%s = '%s'"%(dt, key, filters.get(key)))
|
||||
|
||||
return " and {}".format(" and ".join(conditions)) if conditions else ""
|
||||
|
||||
Reference in New Issue
Block a user