From a985f8524cc7b384a48499f92818e730392d525a Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 13 Jun 2023 16:41:27 +0200 Subject: [PATCH] repair Location --- msp/hooked_methods.py | 27 +++++++++++++++++++++++++++ msp/hooks.py | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 msp/hooked_methods.py diff --git a/msp/hooked_methods.py b/msp/hooked_methods.py new file mode 100644 index 0000000..8b1c77b --- /dev/null +++ b/msp/hooked_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 \ No newline at end of file diff --git a/msp/hooks.py b/msp/hooks.py index 0a3842f..48b68d9 100644 --- a/msp/hooks.py +++ b/msp/hooks.py @@ -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" } }