repair Location

This commit is contained in:
Dave 2023-06-13 16:41:27 +02:00
parent b141c968ea
commit a985f8524c
2 changed files with 28 additions and 1 deletions

27
msp/hooked_methods.py Normal file
View 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

View File

@ -91,7 +91,7 @@ doctype_js = {"Location" : "public/js/location.js"}
doc_events = {
"Location": {
"before_save": "msp.tools.hooks_methods.build_full_location_path"
"before_save": "msp.hooked_methods.build_full_location_path"
}
}