#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

This commit is contained in:
Jordi Albert 2022-09-05 12:32:57 +02:00
parent 086d7782e7
commit 1a1fe4b98c
2 changed files with 27 additions and 2 deletions

View File

@ -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",

View File

@ -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):