update mapping of data return for a lead
This commit is contained in:
parent
948c0b07a4
commit
e7a6bd8ed2
3 changed files with 49 additions and 10 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue