From d295ad907c474a7857de706e1a791e31bede23c4 Mon Sep 17 00:00:00 2001 From: Jordi Albert <63541019+jarg1023@users.noreply.github.com> Date: Mon, 5 Sep 2022 10:12:37 +0200 Subject: [PATCH 01/10] #27 | Sort IPs in list. Added support for IPv6 so it can be sorted as well --- msp/msp/doctype/ip_network/ip_network.py | 12 +++++++++--- .../ip_network_reserved_range.json | 10 +++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/msp/msp/doctype/ip_network/ip_network.py b/msp/msp/doctype/ip_network/ip_network.py index 9bff55c..e433fac 100644 --- a/msp/msp/doctype/ip_network/ip_network.py +++ b/msp/msp/doctype/ip_network/ip_network.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import frappe +import socket from ipaddress import IPv4Address, IPv4Network from frappe.model.document import Document @@ -16,6 +17,7 @@ class IPNetwork(Document): SELECT ipa.name as ip_address_name, ipa.ip_address, + ipa.protocol, ito.name as it_object_name, ito.title, ito.type, @@ -35,15 +37,19 @@ class IPNetwork(Document): used_ips.append({ 'ip_address': ip_network_reserved_range.start, 'title': ip_network_reserved_range.type, - 'type': 'DHCP Range Start' + 'type': 'DHCP Range Start', + 'protocol': ip_network_reserved_range.protocol }) used_ips.append({ 'ip_address': ip_network_reserved_range.end, 'title': ip_network_reserved_range.type, - 'type': 'DHCP Range End' + 'type': 'DHCP Range End', + 'protocol': ip_network_reserved_range.protocol }) - return used_ips + # Sorting method is using inet_pton built in function which is used to convert IPs from string format to a packed, binary format to be able to compare them. It supports IPv4 and IPv6 IPs + # @see https://docs.python.org/3/library/socket.html#socket.inet_pton and https://stackoverflow.com/a/6545090 for more information + return sorted(used_ips, key=lambda item: socket.inet_pton(socket.AF_INET if item['protocol'] == 'IPv4' or not item['protocol'] else socket.AF_INET6 , item['ip_address'])) @frappe.whitelist() def calculate_network_data(doc): diff --git a/msp/msp/doctype/ip_network_reserved_range/ip_network_reserved_range.json b/msp/msp/doctype/ip_network_reserved_range/ip_network_reserved_range.json index 993669f..cc0f7f6 100644 --- a/msp/msp/doctype/ip_network_reserved_range/ip_network_reserved_range.json +++ b/msp/msp/doctype/ip_network_reserved_range/ip_network_reserved_range.json @@ -9,6 +9,7 @@ "start", "end", "type", + "protocol", "description" ], "fields": [ @@ -35,12 +36,19 @@ "fieldname": "description", "fieldtype": "Text Editor", "label": "Description" + }, + { + "default": "IPv4", + "fieldname": "protocol", + "fieldtype": "Select", + "label": "Protocol", + "options": "IPv4\nIPv6" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2022-08-17 13:44:07.476976", + "modified": "2022-09-05 09:57:47.527108", "modified_by": "Administrator", "module": "MSP", "name": "IP Network Reserved Range", From 1a1fe4b98ca368e60d331ab0b882f77adb3c5fbe Mon Sep 17 00:00:00 2001 From: Jordi Albert <63541019+jarg1023@users.noreply.github.com> Date: Mon, 5 Sep 2022 12:32:57 +0200 Subject: [PATCH 02/10] #29 | Link IP Address to IT Object in a more centralized way. Now it is controlled from the IT Object. Also added new field to IP Address to display IT Object title to make more clear to which device is related --- msp/msp/doctype/ip_address/ip_address.json | 12 ++++++++++-- msp/msp/doctype/it_object/it_object.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/msp/msp/doctype/ip_address/ip_address.json b/msp/msp/doctype/ip_address/ip_address.json index 4b1f6d1..a8692fd 100644 --- a/msp/msp/doctype/ip_address/ip_address.json +++ b/msp/msp/doctype/ip_address/ip_address.json @@ -10,6 +10,7 @@ "title", "ip_address", "protocol", + "it_object_name", "it_object", "ip_network", "it_landscape" @@ -37,7 +38,8 @@ "fieldname": "it_object", "fieldtype": "Link", "label": "IT Object", - "options": "IT Object" + "options": "IT Object", + "read_only": 1 }, { "fieldname": "it_landscape", @@ -52,10 +54,16 @@ "label": "IP Network", "options": "IP Network", "reqd": 1 + }, + { + "fieldname": "it_object_name", + "fieldtype": "Data", + "label": "IT Object Name", + "read_only": 1 } ], "links": [], - "modified": "2022-06-17 11:21:47.850521", + "modified": "2022-09-05 12:03:39.294521", "modified_by": "Administrator", "module": "MSP", "name": "IP Address", diff --git a/msp/msp/doctype/it_object/it_object.py b/msp/msp/doctype/it_object/it_object.py index 7312138..ba6ca1d 100644 --- a/msp/msp/doctype/it_object/it_object.py +++ b/msp/msp/doctype/it_object/it_object.py @@ -8,6 +8,23 @@ import requests from frappe.model.document import Document class ITObject(Document): + def save(self, *args, **kwargs): + super().save(*args, **kwargs) + if not self.main_ip: + return + + ip_address_name_with_it_object = frappe.db.get_value("IP Address", {'it_object': self.name}, ['name']) + if ip_address_name_with_it_object: + current_ip_address_with_it_object_doctype = frappe.get_doc("IP Address", ip_address_name_with_it_object) + current_ip_address_with_it_object_doctype.it_object = None + current_ip_address_with_it_object_doctype.it_object_name = None + current_ip_address_with_it_object_doctype.save() + + ip_address_doctype = frappe.get_doc("IP Address", self.main_ip) + ip_address_doctype.it_object = self.name + ip_address_doctype.it_object_name = self.title + ip_address_doctype.save() + frappe.db.commit() def get_host_status_from_hosts_data(self, hosts_data, msp_settings_doc): From 0798926d24d3e2ee383ced2e83d5d8cc367d25a2 Mon Sep 17 00:00:00 2001 From: Jordi Albert <63541019+jarg1023@users.noreply.github.com> Date: Mon, 5 Sep 2022 15:53:35 +0200 Subject: [PATCH 03/10] #13 | Export customization for ToDO Doctype to add custom relations with MSP Doctypes --- msp/msp/custom/todo.json | 308 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 308 insertions(+) create mode 100644 msp/msp/custom/todo.json diff --git a/msp/msp/custom/todo.json b/msp/msp/custom/todo.json new file mode 100644 index 0000000..80fe3f8 --- /dev/null +++ b/msp/msp/custom/todo.json @@ -0,0 +1,308 @@ +{ + "custom_fields": [ + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2022-09-05 12:52:53.000762", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "ToDo", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "ip_network", + "fieldtype": "Link", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "idx": 19, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "assignment_rule", + "label": "IP Network", + "length": 0, + "mandatory_depends_on": null, + "modified": "2022-09-05 12:52:53.000762", + "modified_by": "Administrator", + "name": "ToDo-ip_network", + "no_copy": 0, + "non_negative": 0, + "options": "IP Network", + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2022-09-05 12:56:53.645299", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "ToDo", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "it_landscape", + "fieldtype": "Link", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "idx": 20, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "ip_network", + "label": "IT Landscape", + "length": 0, + "mandatory_depends_on": null, + "modified": "2022-09-05 12:56:53.645299", + "modified_by": "Administrator", + "name": "ToDo-it_landscape", + "no_copy": 0, + "non_negative": 0, + "options": "IT Landscape", + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2022-09-05 12:56:53.920916", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "ToDo", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "it_object", + "fieldtype": "Link", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "idx": 21, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "it_landscape", + "label": "IT Object", + "length": 0, + "mandatory_depends_on": null, + "modified": "2022-09-05 12:56:53.920916", + "modified_by": "Administrator", + "name": "ToDo-it_object", + "no_copy": 0, + "non_negative": 0, + "options": "IT Object", + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2022-09-05 12:56:54.064975", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "ToDo", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "ip_address", + "fieldtype": "Link", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "idx": 22, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "it_object", + "label": "IP Address", + "length": 0, + "mandatory_depends_on": null, + "modified": "2022-09-05 12:56:54.064975", + "modified_by": "Administrator", + "name": "ToDo-ip_address", + "no_copy": 0, + "non_negative": 0, + "options": "IP Address", + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2022-09-05 13:10:58.880444", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "ToDo", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "it_user_account", + "fieldtype": "Link", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "idx": 22, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "ip_address", + "label": "IT User Account", + "length": 0, + "mandatory_depends_on": null, + "modified": "2022-09-05 13:10:58.880444", + "modified_by": "Administrator", + "name": "ToDo-it_user_account", + "no_copy": 0, + "non_negative": 0, + "options": "IT User Account", + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + } + ], + "custom_perms": [], + "doctype": "ToDo", + "property_setters": [], + "sync_on_migrate": 1 +} \ No newline at end of file From db36f11633f01d44efbbae6c179af52cc53bb076 Mon Sep 17 00:00:00 2001 From: Jordi Albert <63541019+jarg1023@users.noreply.github.com> Date: Mon, 5 Sep 2022 15:54:28 +0200 Subject: [PATCH 04/10] #13 | Add relation to ToDo Doctype in dashboards information and create needed dashboards --- msp/msp/doctype/ip_address/ip_address_dashboard.py | 14 ++++++++++++++ msp/msp/doctype/ip_network/ip_network_dashboard.py | 4 ++++ .../doctype/it_landscape/it_landscape_dashboard.py | 2 +- msp/msp/doctype/it_object/it_object_dashboard.py | 14 ++++++++++++++ .../it_user_account/it_user_account_dashboard.py | 14 ++++++++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 msp/msp/doctype/ip_address/ip_address_dashboard.py create mode 100644 msp/msp/doctype/it_object/it_object_dashboard.py create mode 100644 msp/msp/doctype/it_user_account/it_user_account_dashboard.py diff --git a/msp/msp/doctype/ip_address/ip_address_dashboard.py b/msp/msp/doctype/ip_address/ip_address_dashboard.py new file mode 100644 index 0000000..e2d4eb9 --- /dev/null +++ b/msp/msp/doctype/ip_address/ip_address_dashboard.py @@ -0,0 +1,14 @@ +from __future__ import unicode_literals +from frappe import _ + +def get_data(): + return { + 'heatmap': False, + 'fieldname': 'ip_address', + 'transactions': [ + { + 'label': _('Processes'), + 'items': ['ToDo'] + } + ] + } diff --git a/msp/msp/doctype/ip_network/ip_network_dashboard.py b/msp/msp/doctype/ip_network/ip_network_dashboard.py index 9ccf345..71feceb 100644 --- a/msp/msp/doctype/ip_network/ip_network_dashboard.py +++ b/msp/msp/doctype/ip_network/ip_network_dashboard.py @@ -9,6 +9,10 @@ def get_data(): { 'label': _('Objects'), 'items': ['IP Address' ] + }, + { + 'label': _('Processes'), + 'items': ['ToDo' ] } ] } diff --git a/msp/msp/doctype/it_landscape/it_landscape_dashboard.py b/msp/msp/doctype/it_landscape/it_landscape_dashboard.py index 3b57d2f..7f66ea2 100644 --- a/msp/msp/doctype/it_landscape/it_landscape_dashboard.py +++ b/msp/msp/doctype/it_landscape/it_landscape_dashboard.py @@ -13,7 +13,7 @@ def get_data(): }, { 'label': _('Processes'), - 'items': ['IT Contract'] + 'items': ['IT Contract', 'ToDo'] } ] } diff --git a/msp/msp/doctype/it_object/it_object_dashboard.py b/msp/msp/doctype/it_object/it_object_dashboard.py new file mode 100644 index 0000000..1721e13 --- /dev/null +++ b/msp/msp/doctype/it_object/it_object_dashboard.py @@ -0,0 +1,14 @@ +from __future__ import unicode_literals +from frappe import _ + +def get_data(): + return { + 'heatmap': False, + 'fieldname': 'it_object', + 'transactions': [ + { + 'label': _('Processes'), + 'items': ['ToDo'] + } + ] + } diff --git a/msp/msp/doctype/it_user_account/it_user_account_dashboard.py b/msp/msp/doctype/it_user_account/it_user_account_dashboard.py new file mode 100644 index 0000000..421ec63 --- /dev/null +++ b/msp/msp/doctype/it_user_account/it_user_account_dashboard.py @@ -0,0 +1,14 @@ +from __future__ import unicode_literals +from frappe import _ + +def get_data(): + return { + 'heatmap': False, + 'fieldname': 'it_user_account', + 'transactions': [ + { + 'label': _('Processes'), + 'items': ['ToDo'] + } + ] + } From 7a5746fd27981e18a0714eb4b11993a779ac3b71 Mon Sep 17 00:00:00 2001 From: Jordi Albert <63541019+jarg1023@users.noreply.github.com> Date: Tue, 6 Sep 2022 09:32:30 +0200 Subject: [PATCH 05/10] #29 | Create method to set IT Object data in IP Address Doctypes in already existing doctypes --- msp/msp/doctype/it_object/it_object.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/msp/msp/doctype/it_object/it_object.py b/msp/msp/doctype/it_object/it_object.py index ba6ca1d..48594f3 100644 --- a/msp/msp/doctype/it_object/it_object.py +++ b/msp/msp/doctype/it_object/it_object.py @@ -10,6 +10,9 @@ from frappe.model.document import Document class ITObject(Document): def save(self, *args, **kwargs): super().save(*args, **kwargs) + self.set_it_object_data_in_ip_address_doctype() + + def set_it_object_data_in_ip_address_doctype(self): if not self.main_ip: return @@ -92,3 +95,9 @@ class ITObject(Document): 'status': 500, 'response': f'Data could not be fetched from {msp_settings_doc.oitc_url}. Error -> {str(exception)}' } + +def set_it_object_data_in_ip_address_doctype_for_existing_it_objects(): + it_objects = frappe.db.get_all("IT Object", fields=['name']) + for it_object in it_objects: + it_object_doctype = frappe.get_doc("IT Object", it_object['name']) + it_object_doctype.set_it_object_data_in_ip_address_doctype() From 6e29d0f6bf2c71c82335853e5b60b65be64a679d Mon Sep 17 00:00:00 2001 From: Jordi Albert <63541019+jarg1023@users.noreply.github.com> Date: Tue, 6 Sep 2022 16:48:54 +0200 Subject: [PATCH 06/10] #12 | Customize Location Doctype --- msp/msp/custom/location.json | 237 +++++++++++++++++++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 msp/msp/custom/location.json diff --git a/msp/msp/custom/location.json b/msp/msp/custom/location.json new file mode 100644 index 0000000..231f59c --- /dev/null +++ b/msp/msp/custom/location.json @@ -0,0 +1,237 @@ +{ + "custom_fields": [ + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2022-09-06 09:39:15.583037", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "Location", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "full_path", + "fieldtype": "Data", + "hidden": 1, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "idx": 4, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "html_full_path", + "label": "Full Path", + "length": 1000, + "mandatory_depends_on": null, + "modified": "2022-09-06 09:39:15.583037", + "modified_by": "Administrator", + "name": "Location-full_path", + "no_copy": 0, + "non_negative": 0, + "options": null, + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 1, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2022-09-06 15:02:44.835105", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "Location", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "html_full_path", + "fieldtype": "Text Editor", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "idx": 3, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "parent_location", + "label": "HTML Full Path", + "length": 0, + "mandatory_depends_on": null, + "modified": "2022-09-06 15:02:44.835105", + "modified_by": "Administrator", + "name": "Location-html_full_path", + "no_copy": 0, + "non_negative": 0, + "options": null, + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 1, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 0, + "unique": 0, + "width": null + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2022-09-06 15:12:53.892684", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "Location", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "type", + "fieldtype": "Select", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "idx": 5, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_preview": 0, + "in_standard_filter": 1, + "insert_after": "full_path", + "label": "Type", + "length": 0, + "mandatory_depends_on": null, + "modified": "2022-09-06 15:12:53.892684", + "modified_by": "Administrator", + "name": "Location-type", + "no_copy": 0, + "non_negative": 0, + "options": "\nCountry\nState\nCity\nStreet\nBuilding\nFloor\nRoom\nRack\nHU", + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "translatable": 1, + "unique": 0, + "width": null + } + ], + "custom_perms": [], + "doctype": "Location", + "property_setters": [ + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "creation": "2022-09-06 13:12:35.858567", + "default_value": null, + "doc_type": "Location", + "docstatus": 0, + "doctype_or_field": "DocType", + "field_name": null, + "idx": 0, + "modified": "2022-09-06 13:12:35.858567", + "modified_by": "Administrator", + "name": "Location-main-search_fields", + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "property": "search_fields", + "property_type": "Data", + "row_name": null, + "value": "location_name, full_path" + }, + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "creation": "2022-09-06 09:37:34.757324", + "default_value": null, + "doc_type": "Location", + "docstatus": 0, + "doctype_or_field": "DocType", + "field_name": null, + "idx": 0, + "modified": "2022-09-06 09:37:34.757324", + "modified_by": "Administrator", + "name": "Location-main-autoname", + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "property": "autoname", + "property_type": "Data", + "row_name": null, + "value": "LOC-.#####" + } + ], + "sync_on_migrate": 1 +} \ No newline at end of file From 57847c1c4a5e7e132b379c6375b1366c15731b4e Mon Sep 17 00:00:00 2001 From: Jordi Albert <63541019+jarg1023@users.noreply.github.com> Date: Tue, 6 Sep 2022 16:49:26 +0200 Subject: [PATCH 07/10] #12 | Create custom full path for Location and 'breadcrumbs' --- msp/hooks.py | 10 +++++----- msp/tools/hooks_methods.py | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 msp/tools/hooks_methods.py diff --git a/msp/hooks.py b/msp/hooks.py index 5df4a86..1a24064 100644 --- a/msp/hooks.py +++ b/msp/hooks.py @@ -87,11 +87,11 @@ jenv = { # --------------- # Hook on document methods and events -# doc_events = { -# "Customer": { -# "on_update": "msp.msp.customer_quick_entry.custom_customer_info" -# } -# } +doc_events = { + "Location": { + "before_save": "msp.tools.hooks_methods.build_full_location_path" + } +} # Scheduled Tasks # --------------- diff --git a/msp/tools/hooks_methods.py b/msp/tools/hooks_methods.py new file mode 100644 index 0000000..962d83f --- /dev/null +++ b/msp/tools/hooks_methods.py @@ -0,0 +1,27 @@ +import frappe +from frappe.utils import cstr + +def build_full_location_path(doctype, method=None): + parent_location_name = doctype.parent_location + full_path = '' + html_full_path = '' + has_parent_location = True if parent_location_name else False + + while has_parent_location: + result = frappe.db.get_value('Location', {'name': parent_location_name}, ['name', 'location_name', 'parent_location'], as_dict=True) + if not result: + has_parent_location = False + continue + + full_path = f"{result['location_name']} --> {full_path}" + html_full_path = f"{result['location_name']} --> {html_full_path}" + parent_location_name = result['parent_location'] + + if not parent_location_name: + has_parent_location = False + + full_path = f"{full_path} {doctype.location_name}" if full_path != '' else doctype.location_name + html_full_path = f"{html_full_path} {doctype.location_name}" if html_full_path != '' else f"{doctype.location_name}" + + doctype.full_path = full_path + doctype.html_full_path = html_full_path From cc6c792cd3aebfb1da07c9be572184eb7488134b Mon Sep 17 00:00:00 2001 From: Jordi Albert <63541019+jarg1023@users.noreply.github.com> Date: Tue, 6 Sep 2022 16:50:02 +0200 Subject: [PATCH 08/10] #12 | Modify Doctypes to show new breadcrumbs for location to simplify navigation --- msp/msp/doctype/ip_network/ip_network.json | 10 +++++++++- msp/msp/doctype/it_object/it_object.json | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/msp/msp/doctype/ip_network/ip_network.json b/msp/msp/doctype/ip_network/ip_network.json index 2cf5750..ae54fed 100644 --- a/msp/msp/doctype/ip_network/ip_network.json +++ b/msp/msp/doctype/ip_network/ip_network.json @@ -27,6 +27,7 @@ "it_landscape", "description", "customer", + "location_full_path", "location", "ip_network_reserved_ranges_section", "ip_network_reserved_ranges_table", @@ -172,10 +173,17 @@ "fieldtype": "HTML", "label": "Usage Overview Table", "options": "