mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-24 07:29:22 +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 end: End date-time.
|
||||||
:param filters: Filters (JSON).
|
:param filters: Filters (JSON).
|
||||||
"""
|
"""
|
||||||
condition = ''
|
|
||||||
values = {
|
|
||||||
"start_date": getdate(start),
|
|
||||||
"end_date": getdate(end)
|
|
||||||
}
|
|
||||||
|
|
||||||
if filters:
|
if filters:
|
||||||
if isinstance(filters, basestring):
|
filters = json.loads(filters)
|
||||||
filters = json.loads(filters)
|
else:
|
||||||
|
filters = []
|
||||||
|
|
||||||
if filters.get('holiday_list'):
|
if start:
|
||||||
condition = 'and hlist.name=%(holiday_list)s'
|
filters.append(['Holiday', 'holiday_date', '>', getdate(start)])
|
||||||
values['holiday_list'] = filters['holiday_list']
|
if end:
|
||||||
|
filters.append(['Holiday', 'holiday_date', '<', getdate(end)])
|
||||||
|
|
||||||
data = frappe.db.sql("""select hlist.name, h.holiday_date, h.description
|
return frappe.get_list('Holiday List',
|
||||||
from `tabHoliday List` hlist, tabHoliday h
|
fields=['name', '`tabHoliday`.holiday_date', '`tabHoliday`.description'],
|
||||||
where h.parent = hlist.name
|
filters = filters,
|
||||||
and h.holiday_date is not null
|
update={"allDay": 1})
|
||||||
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
|
|
||||||
|
|||||||
@@ -400,7 +400,7 @@ def is_lwp(leave_type):
|
|||||||
return lwp and cint(lwp[0][0]) or 0
|
return lwp and cint(lwp[0][0]) or 0
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_events(start, end):
|
def get_events(start, end, filters=None):
|
||||||
events = []
|
events = []
|
||||||
|
|
||||||
employee = frappe.db.get_value("Employee", {"user_id": frappe.session.user}, ["name", "company"],
|
employee = frappe.db.get_value("Employee", {"user_id": frappe.session.user}, ["name", "company"],
|
||||||
@@ -411,14 +411,14 @@ def get_events(start, end):
|
|||||||
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 build_match_conditions
|
from frappe.desk.reportview import get_filters_cond
|
||||||
match_conditions = build_match_conditions("Leave Application")
|
conditions = get_filters_cond("Leave Application")
|
||||||
|
|
||||||
# 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, match_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)
|
||||||
|
|||||||
@@ -9,9 +9,8 @@ from frappe import _
|
|||||||
import json
|
import json
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from erpnext.controllers.queries import get_match_cond
|
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.document import Document
|
||||||
from frappe.model.mapper import get_mapped_doc
|
|
||||||
from erpnext.manufacturing.doctype.workstation.workstation import (check_if_within_operating_hours,
|
from erpnext.manufacturing.doctype.workstation.workstation import (check_if_within_operating_hours,
|
||||||
WorkstationHolidayError)
|
WorkstationHolidayError)
|
||||||
from erpnext.manufacturing.doctype.manufacturing_settings.manufacturing_settings import get_mins_between_operations
|
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).
|
:param filters: Filters (JSON).
|
||||||
"""
|
"""
|
||||||
filters = json.loads(filters)
|
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,
|
return frappe.db.sql("""select `tabTimesheet Detail`.name as name,
|
||||||
`tabTimesheet Detail`.docstatus as status, `tabTimesheet Detail`.parent as parent,
|
`tabTimesheet Detail`.docstatus as status, `tabTimesheet Detail`.parent as parent,
|
||||||
from_time as start_date, hours, activity_type,
|
from_time as start_date, hours, activity_type,
|
||||||
@@ -381,15 +381,3 @@ def get_events(start, end, filters=None):
|
|||||||
"end": end
|
"end": end
|
||||||
}, as_dict=True, update={"allDay": 0})
|
}, 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