mirror of
				https://github.com/itsdave-de/msp.git
				synced 2025-10-30 00:47:10 -03:00 
			
		
		
		
	#12 | Create custom full path for Location and 'breadcrumbs'
This commit is contained in:
		
							parent
							
								
									6e29d0f6bf
								
							
						
					
					
						commit
						57847c1c4a
					
				
							
								
								
									
										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 | ||||
| # --------------- | ||||
|  | ||||
							
								
								
									
										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