update mapping of data return for a lead
This commit is contained in:
parent
fcd0489982
commit
4401a541eb
3 changed files with 48 additions and 9 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import frappe, json
|
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
|
# 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)
|
return build_error_response(f"Client '{client_name}' not found as Customer or Lead.", 404)
|
||||||
print("DEBUG: Retrieved customer/lead document:", customer.as_dict())
|
print("DEBUG: Retrieved customer/lead document:", customer.as_dict())
|
||||||
clientData = {**clientData, **customer.as_dict()}
|
clientData = {**clientData, **customer.as_dict()}
|
||||||
|
if customer.doctype == "Lead":
|
||||||
|
clientData.update(map_lead_client(clientData))
|
||||||
links = []
|
links = []
|
||||||
if customer.doctype == "Customer":
|
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:
|
else:
|
||||||
links = frappe.get_all(
|
links = frappe.get_all(
|
||||||
"Dynamic Link",
|
"Dynamic Link",
|
||||||
|
|
@ -124,10 +133,11 @@ def get_client(client_name):
|
||||||
|
|
||||||
print("DEBUG: Retrieved links from lead:", links)
|
print("DEBUG: Retrieved links from lead:", links)
|
||||||
for link in links:
|
for link in links:
|
||||||
linked_doc = frappe.get_doc(link.link_doctype, link.link_name)
|
print("DEBUG: Processing link:", link)
|
||||||
if link.link_doctype == "Contact":
|
linked_doc = frappe.get_doc(link["link_doctype"], link["link_name"])
|
||||||
|
if link["link_doctype"] == "Contact":
|
||||||
clientData["contacts"].append(linked_doc.as_dict())
|
clientData["contacts"].append(linked_doc.as_dict())
|
||||||
elif link.link_doctype == "Address":
|
elif link["link_doctype"] == "Address":
|
||||||
clientData["addresses"].append(linked_doc.as_dict())
|
clientData["addresses"].append(linked_doc.as_dict())
|
||||||
# TODO: Continue getting other linked docs like jobs, invoices, etc.
|
# TODO: Continue getting other linked docs like jobs, invoices, etc.
|
||||||
return build_success_response(clientData)
|
return build_success_response(clientData)
|
||||||
|
|
|
||||||
|
|
@ -158,4 +158,31 @@ def build_full_address(doc):
|
||||||
if first and second:
|
if first and second:
|
||||||
return f"{first}, {second}"
|
return f"{first}, {second}"
|
||||||
return first or second or ""
|
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
|
||||||
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="overview-container">
|
<div class="overview-container">
|
||||||
<!-- Form Mode (new=true or edit mode) -->
|
|
||||||
<template v-if="isNew || editMode">
|
<template v-if="isNew || editMode">
|
||||||
<ClientInformationForm
|
<ClientInformationForm
|
||||||
ref="clientInfoRef"
|
ref="clientInfoRef"
|
||||||
v-model:form-data="formData"
|
:form-data="formData"
|
||||||
|
@update:form-data="formData = $event"
|
||||||
:is-submitting="isSubmitting"
|
:is-submitting="isSubmitting"
|
||||||
:is-edit-mode="editMode"
|
:is-edit-mode="editMode"
|
||||||
@new-client-toggle="handleNewClientToggle"
|
@new-client-toggle="handleNewClientToggle"
|
||||||
|
|
@ -13,7 +13,8 @@
|
||||||
|
|
||||||
<ContactInformationForm
|
<ContactInformationForm
|
||||||
ref="contactInfoRef"
|
ref="contactInfoRef"
|
||||||
v-model:form-data="formData"
|
:form-data="formData"
|
||||||
|
@update:form-data="formData = $event"
|
||||||
:is-submitting="isSubmitting"
|
:is-submitting="isSubmitting"
|
||||||
:is-edit-mode="editMode"
|
:is-edit-mode="editMode"
|
||||||
:is-new-client-locked="isNewClientMode"
|
:is-new-client-locked="isNewClientMode"
|
||||||
|
|
@ -22,7 +23,8 @@
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<AddressInformationForm
|
<AddressInformationForm
|
||||||
v-model:form-data="formData"
|
:form-data="formData"
|
||||||
|
@update:form-data="formData = $event"
|
||||||
:is-submitting="isSubmitting"
|
:is-submitting="isSubmitting"
|
||||||
:is-edit-mode="editMode"
|
:is-edit-mode="editMode"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue