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/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 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": "
Used IPs expected
" + }, + { + "fetch_from": "location.html_full_path", + "fieldname": "location_full_path", + "fieldtype": "Text Editor", + "label": "Location Full Path", + "read_only": 1 } ], "links": [], - "modified": "2022-08-18 10:28:34.233288", + "modified": "2022-09-06 16:39:46.172950", "modified_by": "Administrator", "module": "MSP", "name": "IP Network", diff --git a/msp/msp/doctype/it_object/it_object.json b/msp/msp/doctype/it_object/it_object.json index 35d9320..d5c0771 100644 --- a/msp/msp/doctype/it_object/it_object.json +++ b/msp/msp/doctype/it_object/it_object.json @@ -16,6 +16,7 @@ "item", "customer", "it_landscape", + "location_full_path", "location", "monitoring_section", "oitc_output", @@ -156,11 +157,18 @@ "fieldtype": "HTML", "label": "OITC Output", "options": "
OITC output expected
" + }, + { + "fetch_from": "location.html_full_path", + "fieldname": "location_full_path", + "fieldtype": "Text Editor", + "label": "Location Full Path", + "read_only": 1 } ], "image_field": "image", "links": [], - "modified": "2022-07-18 15:05:40.504305", + "modified": "2022-09-06 16:18:52.084632", "modified_by": "Administrator", "module": "MSP", "name": "IT Object", 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