mirror of
https://github.com/itsdave-de/msp.git
synced 2025-05-06 07:25:13 +02:00
Merge pull request #32 from itsdave-de/feature/12-locations-for-objects
Improve core Location Doctype
This commit is contained in:
commit
399f5f8481
10
msp/hooks.py
10
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
|
||||
# ---------------
|
||||
|
237
msp/msp/custom/location.json
Normal file
237
msp/msp/custom/location.json
Normal file
@ -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
|
||||
}
|
@ -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": "<div id=\"usage-overview-table\">Used IPs expected</div>"
|
||||
},
|
||||
{
|
||||
"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",
|
||||
|
@ -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": "<div id=\"oitc-output\">OITC output expected</div>"
|
||||
},
|
||||
{
|
||||
"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",
|
||||
|
27
msp/tools/hooks_methods.py
Normal file
27
msp/tools/hooks_methods.py
Normal file
@ -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"<a href='http://{cstr(frappe.local.site)}/app/location/{result['name']}' target='_blank'>{result['location_name']}</a> --> {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} <a href='http://{cstr(frappe.local.site)}/app/location/{doctype.name}' target='_blank'>{doctype.location_name}</a>" if html_full_path != '' else f"<a href='{doctype.name}'>{doctype.location_name}</a>"
|
||||
|
||||
doctype.full_path = full_path
|
||||
doctype.html_full_path = html_full_path
|
Loading…
x
Reference in New Issue
Block a user