From 3f10e77d9311ead939cb4ed7a83998fad13d207b Mon Sep 17 00:00:00 2001 From: Jordi Albert <63541019+jarg1023@users.noreply.github.com> Date: Mon, 12 Sep 2022 11:01:57 +0200 Subject: [PATCH 1/2] #33 | Add new custom js to see all IT Objects fileterd by location --- msp/hooks.py | 2 ++ msp/public/js/location.js | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 msp/public/js/location.js diff --git a/msp/hooks.py b/msp/hooks.py index 1a24064..4348ffd 100644 --- a/msp/hooks.py +++ b/msp/hooks.py @@ -39,6 +39,8 @@ jenv = { # doctype_tree_js = {"doctype" : "public/js/doctype_tree.js"} # doctype_calendar_js = {"doctype" : "public/js/doctype_calendar.js"} +doctype_js = {"Location" : "public/js/location.js"} + # Home Pages # ---------- diff --git a/msp/public/js/location.js b/msp/public/js/location.js new file mode 100644 index 0000000..76b5adf --- /dev/null +++ b/msp/public/js/location.js @@ -0,0 +1,7 @@ +frappe.ui.form.on('Location', { + refresh(frm) { + frm.add_custom_button('Show IT Objects in Location', () => { + frappe.set_route('List', 'IT Object', { location_full_path: ['like', `%${frm.doc.location_name}%`] }) + }) + } +}); From 234061f8d1cb976a0ee0f205938213056f6ea266 Mon Sep 17 00:00:00 2001 From: Jordi Albert <63541019+jarg1023@users.noreply.github.com> Date: Mon, 12 Sep 2022 16:09:35 +0200 Subject: [PATCH 2/2] #33 | Get all child locations for a particular location set the filter --- msp/hooks.py | 3 +++ msp/overrides/location/CustomLocation.py | 18 ++++++++++++++++++ msp/overrides/location/__init__.py | 0 msp/public/js/location.js | 5 ++++- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 msp/overrides/location/CustomLocation.py create mode 100644 msp/overrides/location/__init__.py diff --git a/msp/hooks.py b/msp/hooks.py index 4348ffd..9fdebce 100644 --- a/msp/hooks.py +++ b/msp/hooks.py @@ -135,3 +135,6 @@ doc_events = { # "Task": "msp.task.get_dashboard_data" # } +override_doctype_class = { + "Location": "msp.overrides.location.CustomLocation.CustomLocation" +} diff --git a/msp/overrides/location/CustomLocation.py b/msp/overrides/location/CustomLocation.py new file mode 100644 index 0000000..ea210b5 --- /dev/null +++ b/msp/overrides/location/CustomLocation.py @@ -0,0 +1,18 @@ +import frappe +from erpnext.assets.doctype.location.location import Location + +class CustomLocation(Location): + @frappe.whitelist() + def get_all_child_locations_from_location(self): + parent_location_name = self.name + locations_to_filter = [] + return self.search_child_locations(locations_to_filter, parent_location_name) + + def search_child_locations(self, locations_to_filter, parent_location_name): + locations_to_filter.append(parent_location_name) + child_locations = frappe.db.get_list('Location', {'parent_location': parent_location_name}, ['name']) + if child_locations: + for child_location in child_locations: + self.search_child_locations(locations_to_filter, child_location['name']) + + return locations_to_filter diff --git a/msp/overrides/location/__init__.py b/msp/overrides/location/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/msp/public/js/location.js b/msp/public/js/location.js index 76b5adf..6391515 100644 --- a/msp/public/js/location.js +++ b/msp/public/js/location.js @@ -1,7 +1,10 @@ frappe.ui.form.on('Location', { refresh(frm) { frm.add_custom_button('Show IT Objects in Location', () => { - frappe.set_route('List', 'IT Object', { location_full_path: ['like', `%${frm.doc.location_name}%`] }) + frm.call('get_all_child_locations_from_location',{}) + .then((response) => { + frappe.set_route('List', 'IT Object', { location: ['in', `${response.message.toString()}`] }) + }) }) } });