From 5e470f757fb12bb583313955a0ed1b42399818fa Mon Sep 17 00:00:00 2001 From: Zarrar Date: Mon, 4 Dec 2017 11:22:25 +0530 Subject: [PATCH] [Fix] Filter on child table not working in Calendar (#11824) * use the new get_events method * using the common get_events method for calendar_view * using add_fetch to fill customer_name --- .../asset_maintenance_log.py | 23 ---------------- .../asset_maintenance_log_calendar.js | 2 +- .../doctype/training_event/training_event.py | 26 ------------------ .../training_event/training_event_calendar.js | 2 +- .../production_order/production_order.py | 24 ----------------- .../production_order_calendar.js | 2 +- erpnext/projects/doctype/task/task.py | 24 ----------------- .../projects/doctype/task/task_calendar.js | 2 +- .../restaurant_reservation.js | 3 +++ .../restaurant_reservation.py | 27 ------------------- .../restaurant_reservation_calendar.js | 2 +- 11 files changed, 8 insertions(+), 129 deletions(-) diff --git a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.py b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.py index 7c21c24151..f169f01616 100644 --- a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.py +++ b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log.py @@ -44,26 +44,3 @@ class AssetMaintenanceLog(Document): def get_maintenance_tasks(doctype, txt, searchfield, start, page_len, filters): asset_maintenance_tasks = frappe.db.get_values('Asset Maintenance Task', {'parent':filters.get("asset_maintenance")}, 'maintenance_task') return asset_maintenance_tasks - -@frappe.whitelist() -def get_events(start, end, filters=None): - """Returns events for Gantt / Calendar view rendering. - - :param start: Start date-time. - :param end: End date-time. - :param filters: Filters (JSON). - """ - from frappe.desk.calendar import get_event_conditions - conditions = get_event_conditions("Asset Maintenance Log", filters) - data = frappe.db.sql("""select name, due_date, due_date, - task, maintenance_status, asset_name from `tabAsset Maintenance Log` - where ((ifnull(due_date, '0000-00-00')!= '0000-00-00') \ - and (due_date <= %(end)s) \ - or ((ifnull(due_date, '0000-00-00')!= '0000-00-00') \ - and due_date >= %(start)s)) - {conditions}""".format(conditions=conditions), { - "start": start, - "end": end - }, as_dict=True, update={"allDay": 0}) - - return data \ No newline at end of file diff --git a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log_calendar.js b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log_calendar.js index a4978849f0..c804b31e90 100644 --- a/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log_calendar.js +++ b/erpnext/assets/doctype/asset_maintenance_log/asset_maintenance_log_calendar.js @@ -18,5 +18,5 @@ frappe.views.calendar["Asset Maintenance Log"] = { "label": __("Asset Maintenance") } ], - get_events_method: "erpnext.assets.doctype.asset_maintenance_log.asset_maintenance_log.get_events" + get_events_method: "frappe.desk.calendar.get_events" }; diff --git a/erpnext/hr/doctype/training_event/training_event.py b/erpnext/hr/doctype/training_event/training_event.py index 19721005d1..1b13b70f5b 100644 --- a/erpnext/hr/doctype/training_event/training_event.py +++ b/erpnext/hr/doctype/training_event/training_event.py @@ -11,29 +11,3 @@ class TrainingEvent(Document): def validate(self): self.employee_emails = ', '.join(get_employee_emails([d.employee for d in self.employees])) - -@frappe.whitelist() -def get_events(start, end, filters=None): - """Returns events for Gantt / Calendar view rendering. - - :param start: Start date-time. - :param end: End date-time. - :param filters: Filters (JSON). - """ - from frappe.desk.calendar import get_event_conditions - conditions = get_event_conditions("Training Event", filters) - - data = frappe.db.sql(""" - select - name, event_name, event_status, start_time, end_time - from - `tabTraining Event` - where (ifnull(start_time, '0000-00-00')!= '0000-00-00') \ - and (start_time between %(start)s and %(end)s) - and docstatus < 2 - {conditions} - """.format(conditions=conditions), { - "start": start, - "end": end - }, as_dict=True, update={"allDay": 0}) - return data diff --git a/erpnext/hr/doctype/training_event/training_event_calendar.js b/erpnext/hr/doctype/training_event/training_event_calendar.js index cb938518a4..cb168c01d5 100644 --- a/erpnext/hr/doctype/training_event/training_event_calendar.js +++ b/erpnext/hr/doctype/training_event/training_event_calendar.js @@ -10,5 +10,5 @@ frappe.views.calendar["Training Event"] = { "allDay": "allDay" }, gantt: true, - get_events_method: "erpnext.hr.doctype.training_event.training_event.get_events", + get_events_method: "frappe.desk.calendar.get_events", } diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py index bf9d3b6674..d45fbde154 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.py +++ b/erpnext/manufacturing/doctype/production_order/production_order.py @@ -561,30 +561,6 @@ def make_stock_entry(production_order_id, purpose, qty=None): stock_entry.get_items() return stock_entry.as_dict() -@frappe.whitelist() -def get_events(start, end, filters=None): - """Returns events for Gantt / Calendar view rendering. - - :param start: Start date-time. - :param end: End date-time. - :param filters: Filters (JSON). - """ - from frappe.desk.calendar import get_event_conditions - conditions = get_event_conditions("Production Order", filters) - - data = frappe.db.sql("""select name, production_item, planned_start_date, - planned_end_date, status - from `tabProduction Order` - where ((ifnull(planned_start_date, '0000-00-00')!= '0000-00-00') \ - and (planned_start_date <= %(end)s) \ - and ((ifnull(planned_start_date, '0000-00-00')!= '0000-00-00') \ - and ifnull(planned_end_date, '2199-12-31 00:00:00') >= %(start)s)) {conditions} - """.format(conditions=conditions), { - "start": start, - "end": end - }, as_dict=True, update={"allDay": 0}) - return data - @frappe.whitelist() def make_timesheet(production_order, company): timesheet = frappe.new_doc("Timesheet") diff --git a/erpnext/manufacturing/doctype/production_order/production_order_calendar.js b/erpnext/manufacturing/doctype/production_order/production_order_calendar.js index 47cac288f4..ce2600aea1 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order_calendar.js +++ b/erpnext/manufacturing/doctype/production_order/production_order_calendar.js @@ -42,5 +42,5 @@ frappe.views.calendar["Production Order"] = { "label": __("WIP Warehouse") } ], - get_events_method: "erpnext.manufacturing.doctype.production_order.production_order.get_events" + get_events_method: "frappe.desk.calendar.get_events" } diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py index 52d9025669..2a1b0e0fc2 100644 --- a/erpnext/projects/doctype/task/task.py +++ b/erpnext/projects/doctype/task/task.py @@ -148,30 +148,6 @@ def check_if_child_exists(name): return frappe.db.sql("""select name from `tabTask` where parent_task = %s""", name) -@frappe.whitelist() -def get_events(start, end, filters=None): - """Returns events for Gantt / Calendar view rendering. - - :param start: Start date-time. - :param end: End date-time. - :param filters: Filters (JSON). - """ - from frappe.desk.calendar import get_event_conditions - conditions = get_event_conditions("Task", filters) - - data = frappe.db.sql("""select name, exp_start_date, exp_end_date, - subject, status, project from `tabTask` - where ((ifnull(exp_start_date, '0000-00-00')!= '0000-00-00') \ - and (exp_start_date <= %(end)s) \ - or ((ifnull(exp_end_date, '0000-00-00')!= '0000-00-00') \ - and exp_end_date >= %(start)s)) - {conditions}""".format(conditions=conditions), { - "start": start, - "end": end - }, as_dict=True, update={"allDay": 0}) - - return data - def get_project(doctype, txt, searchfield, start, page_len, filters): from erpnext.controllers.queries import get_match_cond return frappe.db.sql(""" select name from `tabProject` diff --git a/erpnext/projects/doctype/task/task_calendar.js b/erpnext/projects/doctype/task/task_calendar.js index d7468a56f9..49dbb76a1a 100644 --- a/erpnext/projects/doctype/task/task_calendar.js +++ b/erpnext/projects/doctype/task/task_calendar.js @@ -19,5 +19,5 @@ frappe.views.calendar["Task"] = { "label": __("Project") } ], - get_events_method: "erpnext.projects.doctype.task.task.get_events" + get_events_method: "frappe.desk.calendar.get_events" } diff --git a/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.js b/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.js index 92183384d3..cebd1052a8 100644 --- a/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.js +++ b/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.js @@ -2,6 +2,9 @@ // For license information, please see license.txt frappe.ui.form.on('Restaurant Reservation', { + setup: function(frm) { + frm.add_fetch('customer', 'customer_name', 'customer_name'); + }, refresh: function(frm) { } diff --git a/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.py b/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.py index 63a36f0a6d..f96de44c3d 100644 --- a/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.py +++ b/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.py @@ -12,30 +12,3 @@ class RestaurantReservation(Document): def validate(self): if not self.reservation_end_time: self.reservation_end_time = get_datetime(self.reservation_time) + timedelta(hours=1) - -@frappe.whitelist() -def get_events(start, end, filters=None): - """Returns events for Gantt / Calendar view rendering. - - :param start: Start date-time. - :param end: End date-time. - :param filters: Filters (JSON). - """ - from frappe.desk.calendar import get_event_conditions - conditions = get_event_conditions("Restaurant Reservation", filters) - - data = frappe.db.sql("""select name, reservation_time, - reservation_end_time, customer_name, status, no_of_people - from - `tabRestaurant Reservation` - where - ((ifnull(reservation_time, '0000-00-00')!= '0000-00-00') \ - and (reservation_time <= %(end)s) \ - or ((ifnull(reservation_end_time, '0000-00-00')!= '0000-00-00') \ - and reservation_end_time >= %(start)s)) - {conditions}""".format(conditions=conditions), { - "start": start, - "end": end - }, as_dict=True, update={"allDay": 0}) - - return data diff --git a/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation_calendar.js b/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation_calendar.js index 09e8f8d937..fe3dc57a72 100644 --- a/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation_calendar.js +++ b/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation_calendar.js @@ -14,5 +14,5 @@ frappe.views.calendar["Restaurant Reservation"] = { "label": __("Customer Name") } ], - get_events_method: "erpnext.restaurant.doctype.restaurant_reservation.restaurant_reservation.get_events" + get_events_method: "frappe.desk.calendar.get_events" };