diff --git a/custom_ui/api/db/clients.py b/custom_ui/api/db/clients.py index 717790b..035cb9d 100644 --- a/custom_ui/api/db/clients.py +++ b/custom_ui/api/db/clients.py @@ -1,5 +1,5 @@ import frappe, json -from custom_ui.db_utils import build_error_response, process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response +from custom_ui.db_utils import build_error_response, process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response, map_lead_client # =============================================================================== # CLIENT MANAGEMENT API METHODS @@ -105,9 +105,18 @@ def get_client(client_name): return build_error_response(f"Client '{client_name}' not found as Customer or Lead.", 404) print("DEBUG: Retrieved customer/lead document:", customer.as_dict()) clientData = {**clientData, **customer.as_dict()} + if customer.doctype == "Lead": + clientData.update(map_lead_client(clientData)) links = [] if customer.doctype == "Customer": - links = customer.get("custom_add_contacts", []) + customer.get("custom_select_address", []) + links = ( + [{"link_doctype": "Contact", "link_name": row.contact} + for row in customer.get("custom_add_contacts", [])] + + + [{"link_doctype": "Address", "link_name": row.address} + for row in customer.get("custom_select_address", [])] + ) + else: links = frappe.get_all( "Dynamic Link", @@ -124,10 +133,11 @@ def get_client(client_name): print("DEBUG: Retrieved links from lead:", links) for link in links: - linked_doc = frappe.get_doc(link.link_doctype, link.link_name) - if link.link_doctype == "Contact": + print("DEBUG: Processing link:", link) + linked_doc = frappe.get_doc(link["link_doctype"], link["link_name"]) + if link["link_doctype"] == "Contact": clientData["contacts"].append(linked_doc.as_dict()) - elif link.link_doctype == "Address": + elif link["link_doctype"] == "Address": clientData["addresses"].append(linked_doc.as_dict()) # TODO: Continue getting other linked docs like jobs, invoices, etc. return build_success_response(clientData) diff --git a/custom_ui/db_utils.py b/custom_ui/db_utils.py index aa35bd6..6e7ab96 100644 --- a/custom_ui/db_utils.py +++ b/custom_ui/db_utils.py @@ -158,4 +158,31 @@ def build_full_address(doc): if first and second: return f"{first}, {second}" return first or second or "" + +def map_lead_client(client_data): + mappings = { + "lead_name": "customer_name", + "customer_type": "customer_type", + "territory": "territory", + "company_name": "company" + } + for lead_field, client_field in mappings.items(): + if lead_field in client_data: + print(f"DEBUG: Mapping field {lead_field} to {client_field} with value {client_data[lead_field]}") + client_data[client_field] = client_data[lead_field] + client_data["customer_group"] = "" # Leads don't have customer groups + return client_data + +def map_lead_update(client_data): + mappings = { + "customer_name": "lead_name", + "customer_type": "customer_type", + "territory": "territory", + "company": "company_name" + } + for client_field, lead_field in mappings.items(): + if client_field in client_data: + print(f"DEBUG: Mapping field {client_field} to {lead_field} with value {client_data[client_field]}") + client_data[lead_field] = client_data[client_field] + return client_data \ No newline at end of file diff --git a/frontend/src/components/clientSubPages/Overview.vue b/frontend/src/components/clientSubPages/Overview.vue index 09d3419..46a99ff 100644 --- a/frontend/src/components/clientSubPages/Overview.vue +++ b/frontend/src/components/clientSubPages/Overview.vue @@ -10,11 +10,11 @@ />
- -