#12 | Create custom full path for Location and 'breadcrumbs'

This commit is contained in:
Jordi Albert 2022-09-06 16:49:26 +02:00
parent 6e29d0f6bf
commit 57847c1c4a
2 changed files with 32 additions and 5 deletions

View File

@ -87,11 +87,11 @@ jenv = {
# --------------- # ---------------
# Hook on document methods and events # Hook on document methods and events
# doc_events = { doc_events = {
# "Customer": { "Location": {
# "on_update": "msp.msp.customer_quick_entry.custom_customer_info" "before_save": "msp.tools.hooks_methods.build_full_location_path"
# } }
# } }
# Scheduled Tasks # Scheduled Tasks
# --------------- # ---------------

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