Changed old custom fields names.
This commit is contained in:
parent
d6f7800f20
commit
a034b15c62
1 changed files with 39 additions and 39 deletions
|
|
@ -28,30 +28,30 @@ def get_client_status_counts(weekly=False, week_start_date=None, week_end_date=N
|
||||||
|
|
||||||
onsite_meeting_scheduled_status_counts = {
|
onsite_meeting_scheduled_status_counts = {
|
||||||
"label": "On-Site Meeting Scheduled",
|
"label": "On-Site Meeting Scheduled",
|
||||||
"not_started": frappe.db.count("Address", filters=get_filters("custom_onsite_meeting_scheduled", "Not Started")),
|
"not_started": frappe.db.count("Address", filters=get_filters("onsite_meeting_scheduled", "Not Started")),
|
||||||
"in_progress": frappe.db.count("Address", filters=get_filters("custom_onsite_meeting_scheduled", "In Progress")),
|
"in_progress": frappe.db.count("Address", filters=get_filters("onsite_meeting_scheduled", "In Progress")),
|
||||||
"completed": frappe.db.count("Address", filters=get_filters("custom_onsite_meeting_scheduled", "Completed"))
|
"completed": frappe.db.count("Address", filters=get_filters("onsite_meeting_scheduled", "Completed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
estimate_sent_status_counts = {
|
estimate_sent_status_counts = {
|
||||||
"label": "Estimate Sent",
|
"label": "Estimate Sent",
|
||||||
"not_started": frappe.db.count("Address", filters=get_filters("custom_estimate_sent_status", "Not Started")),
|
"not_started": frappe.db.count("Address", filters=get_filters("estimate_sent_status", "Not Started")),
|
||||||
"in_progress": frappe.db.count("Address", filters=get_filters("custom_estimate_sent_status", "In Progress")),
|
"in_progress": frappe.db.count("Address", filters=get_filters("estimate_sent_status", "In Progress")),
|
||||||
"completed": frappe.db.count("Address", filters=get_filters("custom_estimate_sent_status", "Completed"))
|
"completed": frappe.db.count("Address", filters=get_filters("estimate_sent_status", "Completed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
job_status_counts = {
|
job_status_counts = {
|
||||||
"label": "Job Status",
|
"label": "Job Status",
|
||||||
"not_started": frappe.db.count("Address", filters=get_filters("custom_job_status", "Not Started")),
|
"not_started": frappe.db.count("Address", filters=get_filters("job_status", "Not Started")),
|
||||||
"in_progress": frappe.db.count("Address", filters=get_filters("custom_job_status", "In Progress")),
|
"in_progress": frappe.db.count("Address", filters=get_filters("job_status", "In Progress")),
|
||||||
"completed": frappe.db.count("Address", filters=get_filters("custom_job_status", "Completed"))
|
"completed": frappe.db.count("Address", filters=get_filters("job_status", "Completed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
payment_received_status_counts = {
|
payment_received_status_counts = {
|
||||||
"label": "Payment Received",
|
"label": "Payment Received",
|
||||||
"not_started": frappe.db.count("Address", filters=get_filters("custom_payment_received_status", "Not Started")),
|
"not_started": frappe.db.count("Address", filters=get_filters("payment_received_status", "Not Started")),
|
||||||
"in_progress": frappe.db.count("Address", filters=get_filters("custom_payment_received_status", "In Progress")),
|
"in_progress": frappe.db.count("Address", filters=get_filters("payment_received_status", "In Progress")),
|
||||||
"completed": frappe.db.count("Address", filters=get_filters("custom_payment_received_status", "Completed"))
|
"completed": frappe.db.count("Address", filters=get_filters("payment_received_status", "Completed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
status_dicts = [
|
status_dicts = [
|
||||||
|
|
@ -135,7 +135,7 @@ def get_client(client_name):
|
||||||
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.
|
||||||
print("DEBUG: Final client data prepared:", clientData)
|
print("DEBUG: Final client data prepared:", clientData)
|
||||||
return build_success_response(clientData)
|
return build_success_response(clientData)
|
||||||
|
|
@ -143,7 +143,7 @@ def get_client(client_name):
|
||||||
return build_error_response(str(ve), 400)
|
return build_error_response(str(ve), 400)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return build_error_response(str(e), 500)
|
return build_error_response(str(e), 500)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_client_v2(client_name):
|
def get_client_v2(client_name):
|
||||||
"""Get detailed information for a specific client including address, customer, and projects."""
|
"""Get detailed information for a specific client including address, customer, and projects."""
|
||||||
|
|
@ -159,7 +159,7 @@ def get_client_v2(client_name):
|
||||||
clientData["addresses"] = [AddressService.get_or_throw(link.address) for link in clientData["properties"]]
|
clientData["addresses"] = [AddressService.get_or_throw(link.address) for link in clientData["properties"]]
|
||||||
if clientData["doctype"] == "Lead":
|
if clientData["doctype"] == "Lead":
|
||||||
clientData["customer_name"] = customer.custom_customer_name
|
clientData["customer_name"] = customer.custom_customer_name
|
||||||
|
|
||||||
# TODO: Continue getting other linked docs like jobs, invoices, etc.
|
# TODO: Continue getting other linked docs like jobs, invoices, etc.
|
||||||
print("DEBUG: Final client data prepared:", clientData)
|
print("DEBUG: Final client data prepared:", clientData)
|
||||||
return build_success_response(clientData)
|
return build_success_response(clientData)
|
||||||
|
|
@ -167,9 +167,9 @@ def get_client_v2(client_name):
|
||||||
return build_error_response(str(ve), 400)
|
return build_error_response(str(ve), 400)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return build_error_response(str(e), 500)
|
return build_error_response(str(e), 500)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_clients_table_data_v2(filters={}, sortings=[], page=1, page_size=10):
|
def get_clients_table_data_v2(filters={}, sortings=[], page=1, page_size=10):
|
||||||
"""Get paginated client table data with filtering and sorting support."""
|
"""Get paginated client table data with filtering and sorting support."""
|
||||||
|
|
@ -189,21 +189,21 @@ def get_clients_table_data_v2(filters={}, sortings=[], page=1, page_size=10):
|
||||||
if filters.get("company"):
|
if filters.get("company"):
|
||||||
where_clauses.append("c.company = %s")
|
where_clauses.append("c.company = %s")
|
||||||
values.append(filters["company"]["value"])
|
values.append(filters["company"]["value"])
|
||||||
|
|
||||||
if filters.get("address"):
|
if filters.get("address"):
|
||||||
where_clauses.append("a.full_address LIKE %s")
|
where_clauses.append("a.full_address LIKE %s")
|
||||||
values.append(f"%{filters['address']['value']}%")
|
values.append(f"%{filters['address']['value']}%")
|
||||||
|
|
||||||
if filters.get("customer_name"):
|
if filters.get("customer_name"):
|
||||||
where_clauses.append("a.customer_name LIKE %s")
|
where_clauses.append("a.customer_name LIKE %s")
|
||||||
values.append(f"%{filters['customer_name']['value']}%")
|
values.append(f"%{filters['customer_name']['value']}%")
|
||||||
|
|
||||||
where_sql = ""
|
where_sql = ""
|
||||||
if where_clauses:
|
if where_clauses:
|
||||||
where_sql = "WHERE " + " AND ".join(where_clauses)
|
where_sql = "WHERE " + " AND ".join(where_clauses)
|
||||||
|
|
||||||
offset = (page - 1) * page_size
|
offset = (page - 1) * page_size
|
||||||
|
|
||||||
address_names = frappe.db.sql(f"""
|
address_names = frappe.db.sql(f"""
|
||||||
SELECT DISTINCT a.name
|
SELECT DISTINCT a.name
|
||||||
FROM `tabAddress` a
|
FROM `tabAddress` a
|
||||||
|
|
@ -213,7 +213,7 @@ def get_clients_table_data_v2(filters={}, sortings=[], page=1, page_size=10):
|
||||||
LIMIT %s OFFSET %s
|
LIMIT %s OFFSET %s
|
||||||
""", values + [page_size, offset], as_dict=True)
|
""", values + [page_size, offset], as_dict=True)
|
||||||
print("DEBUG: Address names retrieved:", address_names)
|
print("DEBUG: Address names retrieved:", address_names)
|
||||||
|
|
||||||
count = frappe.db.sql(f"""
|
count = frappe.db.sql(f"""
|
||||||
SELECT COUNT(DISTINCT a.name) as count
|
SELECT COUNT(DISTINCT a.name) as count
|
||||||
FROM `tabAddress` a
|
FROM `tabAddress` a
|
||||||
|
|
@ -230,18 +230,18 @@ def get_clients_table_data_v2(filters={}, sortings=[], page=1, page_size=10):
|
||||||
tableRow["customer_name"] = normalize_name(address.customer_name, "-#-")
|
tableRow["customer_name"] = normalize_name(address.customer_name, "-#-")
|
||||||
tableRow["companies"] = ", ".join([link.company for link in address.get("companies", [])])
|
tableRow["companies"] = ", ".join([link.company for link in address.get("companies", [])])
|
||||||
tableRows.append(tableRow)
|
tableRows.append(tableRow)
|
||||||
|
|
||||||
table_data = build_datatable_dict(data=tableRows, count=count, page=page, page_size=page_size)
|
table_data = build_datatable_dict(data=tableRows, count=count, page=page, page_size=page_size)
|
||||||
|
|
||||||
return build_success_response(table_data)
|
return build_success_response(table_data)
|
||||||
except frappe.ValidationError as ve:
|
except frappe.ValidationError as ve:
|
||||||
return build_error_response(str(ve), 400)
|
return build_error_response(str(ve), 400)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("ERROR in get_clients_table_data_v2:", str(e))
|
print("ERROR in get_clients_table_data_v2:", str(e))
|
||||||
return build_error_response(str(e), 500)
|
return build_error_response(str(e), 500)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
|
|
@ -354,11 +354,11 @@ def upsert_client(data):
|
||||||
try:
|
try:
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
print("#####DEBUG: Create client data received:", data)
|
print("#####DEBUG: Create client data received:", data)
|
||||||
|
|
||||||
customer_name = data.get("customer_name")
|
customer_name = data.get("customer_name")
|
||||||
contacts = data.get("contacts", [])
|
contacts = data.get("contacts", [])
|
||||||
addresses = data.get("addresses", [])
|
addresses = data.get("addresses", [])
|
||||||
|
|
||||||
# Check for existing address
|
# Check for existing address
|
||||||
client_doc = check_and_get_client_doc(customer_name)
|
client_doc = check_and_get_client_doc(customer_name)
|
||||||
if client_doc:
|
if client_doc:
|
||||||
|
|
@ -374,7 +374,7 @@ def upsert_client(data):
|
||||||
return build_error_response("This address already exists. Please use a different address or search for the address to find the associated client.", 400)
|
return build_error_response("This address already exists. Please use a different address or search for the address to find the associated client.", 400)
|
||||||
|
|
||||||
# Handle customer creation/update
|
# Handle customer creation/update
|
||||||
|
|
||||||
print("#####DEBUG: Creating new lead.")
|
print("#####DEBUG: Creating new lead.")
|
||||||
customer_type = data.get("customer_type", "Individual")
|
customer_type = data.get("customer_type", "Individual")
|
||||||
primary_contact = find_primary_contact_or_throw(contacts)
|
primary_contact = find_primary_contact_or_throw(contacts)
|
||||||
|
|
@ -392,7 +392,7 @@ def upsert_client(data):
|
||||||
lead_data["company_name"] = data.get("customer_name")
|
lead_data["company_name"] = data.get("customer_name")
|
||||||
client_doc = create_lead(lead_data)
|
client_doc = create_lead(lead_data)
|
||||||
print(f"#####DEBUG: {client_doc.doctype}:", client_doc.as_dict())
|
print(f"#####DEBUG: {client_doc.doctype}:", client_doc.as_dict())
|
||||||
|
|
||||||
#Handle contact creation
|
#Handle contact creation
|
||||||
contact_docs = []
|
contact_docs = []
|
||||||
for contact_data in contacts:
|
for contact_data in contacts:
|
||||||
|
|
@ -427,7 +427,7 @@ def upsert_client(data):
|
||||||
})
|
})
|
||||||
ContactService.link_contact_to_customer(contact_doc, "Lead", client_doc.name)
|
ContactService.link_contact_to_customer(contact_doc, "Lead", client_doc.name)
|
||||||
contact_docs.append(contact_doc)
|
contact_docs.append(contact_doc)
|
||||||
|
|
||||||
# Link all contacts to client after creating them
|
# Link all contacts to client after creating them
|
||||||
client_doc.reload()
|
client_doc.reload()
|
||||||
for idx, contact_data in enumerate(contacts):
|
for idx, contact_data in enumerate(contacts):
|
||||||
|
|
@ -476,7 +476,7 @@ def upsert_client(data):
|
||||||
primary_contact = contact_docs[address.get("primary_contact)", 0)]
|
primary_contact = contact_docs[address.get("primary_contact)", 0)]
|
||||||
AddressService.set_primary_contact(address_doc.name, primary_contact.name)
|
AddressService.set_primary_contact(address_doc.name, primary_contact.name)
|
||||||
address_docs.append(address_doc)
|
address_docs.append(address_doc)
|
||||||
|
|
||||||
# Link all addresses to client after creating them
|
# Link all addresses to client after creating them
|
||||||
client_doc.reload()
|
client_doc.reload()
|
||||||
for address_doc in address_docs:
|
for address_doc in address_docs:
|
||||||
|
|
@ -487,7 +487,7 @@ def upsert_client(data):
|
||||||
client_dict = client_doc.as_dict()
|
client_dict = client_doc.as_dict()
|
||||||
client_dict["contacts"] = [contact.as_dict() for contact in contact_docs]
|
client_dict["contacts"] = [contact.as_dict() for contact in contact_docs]
|
||||||
client_dict["addresses"] = [address.as_dict() for address in address_docs]
|
client_dict["addresses"] = [address.as_dict() for address in address_docs]
|
||||||
|
|
||||||
frappe.local.message_log = []
|
frappe.local.message_log = []
|
||||||
return build_success_response(client_dict)
|
return build_success_response(client_dict)
|
||||||
except frappe.ValidationError as ve:
|
except frappe.ValidationError as ve:
|
||||||
|
|
@ -535,8 +535,8 @@ def convert_lead_to_customer(lead_name):
|
||||||
lead = frappe.get_doc("Lead", lead_name)
|
lead = frappe.get_doc("Lead", lead_name)
|
||||||
customer = make_customer(lead)
|
customer = make_customer(lead)
|
||||||
customer.insert(ignore_permissions=True)
|
customer.insert(ignore_permissions=True)
|
||||||
|
|
||||||
|
|
||||||
def create_lead(lead_data):
|
def create_lead(lead_data):
|
||||||
lead = frappe.get_doc({
|
lead = frappe.get_doc({
|
||||||
"doctype": "Lead",
|
"doctype": "Lead",
|
||||||
|
|
@ -551,10 +551,10 @@ def get_customer_or_lead(client_name):
|
||||||
else:
|
else:
|
||||||
lead_name = frappe.db.get_all("Lead", pluck="name", filters={"lead_name": client_name})[0]
|
lead_name = frappe.db.get_all("Lead", pluck="name", filters={"lead_name": client_name})[0]
|
||||||
return frappe.get_doc("Lead", lead_name)
|
return frappe.get_doc("Lead", lead_name)
|
||||||
|
|
||||||
def find_primary_contact_or_throw(contacts):
|
def find_primary_contact_or_throw(contacts):
|
||||||
for contact in contacts:
|
for contact in contacts:
|
||||||
if contact.get("is_primary"):
|
if contact.get("is_primary"):
|
||||||
print("#####DEBUG: Primary contact found:", contact)
|
print("#####DEBUG: Primary contact found:", contact)
|
||||||
return contact
|
return contact
|
||||||
raise ValueError("No primary contact found in contacts list.")
|
raise ValueError("No primary contact found in contacts list.")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue