update sidebar layout, update theme, update client table data

This commit is contained in:
Casey 2025-12-16 06:45:50 -06:00
parent 011080e0f8
commit 1a837ffcfc
4 changed files with 109 additions and 63 deletions

View file

@ -154,67 +154,71 @@ def get_client(client_name):
@frappe.whitelist()
def get_clients_table_data(filters={}, sortings=[], page=1, page_size=10):
"""Get paginated client table data with filtering and sorting support."""
# try:
try:
# print("DEBUG: Raw client table query received:", {
# "filters": filters,
# "sortings": sortings,
# "page": page,
# "page_size": page_size
# })
print("DEBUG: Raw client table query received:", {
"filters": filters,
"sortings": sortings,
"page": page,
"page_size": page_size
})
# processed_filters, processed_sortings, is_or, page, page_size = process_query_conditions(filters, sortings, page, page_size)
# print("DEBUG: Processed filters:", processed_filters)
# print("DEBUG: Processed sortings:", processed_sortings)
# # Handle count with proper OR filter support
# if is_or:
# count = frappe.db.sql(*get_count_or_filters("Address", processed_filters))[0][0]
# else:
# count = frappe.db.count("Address", filters=processed_filters)
processed_filters, processed_sortings, is_or, page, page_size = process_query_conditions(filters, sortings, page, page_size)
print("DEBUG: Processed filters:", processed_filters)
print("DEBUG: Processed sortings:", processed_sortings)
# Handle count with proper OR filter support
if is_or:
count = frappe.db.sql(*get_count_or_filters("Address", processed_filters))[0][0]
else:
count = frappe.db.count("Address", filters=processed_filters)
# print("DEBUG: Count of addresses matching filters:", count)
print("DEBUG: Count of addresses matching filters:", count)
# address_names = frappe.db.get_all(
# "Address",
# fields=["name"],
# filters=processed_filters if not is_or else None,
# or_filters=processed_filters if is_or else None,
# limit=page_size,
# start=(page - 1) * page_size,
# order_by=processed_sortings
# )
address_names = frappe.db.get_all(
"Address",
fields=["name"],
filters=processed_filters if not is_or else None,
or_filters=processed_filters if is_or else None,
limit=page_size,
start=(page - 1) * page_size,
order_by=processed_sortings
)
# addresses = [frappe.get_doc("Address", addr["name"]).as_dict() for addr in address_names]
# tableRows = []
# for address in addresses:
# tableRow = {}
# links = address.links
# customer_links = [link for link in links if link.link_doctype == "Customer"] if links else None
# customer_name = address.get("custom_customer_to_bill")
# if not customer_name and not customer_links:
# print("DEBUG: No customer links found and no customer to bill.")
# customer_name = "N/A"
# elif not customer_name and customer_links:
# print("DEBUG: No customer to bill. Customer links found:", customer_links)
# customer_name = customer_links[0].link_name
# tableRow["id"] = address["name"]
# tableRow["customer_name"] = customer_name
# tableRow["address"] = (
# f"{address['address_line1']}"
# f"{' ' + address['address_line2'] if address['address_line2'] else ''} "
# f"{address['city']}, {address['state']} {address['pincode']}"
# )
# tableRow["appointment_scheduled_status"] = address.custom_onsite_meeting_scheduled
# tableRow["estimate_sent_status"] = address.custom_estimate_sent_status
# tableRow["job_status"] = address.custom_job_status
# tableRow["payment_received_status"] = address.custom_payment_received_status
# tableRows.append(tableRow)
# tableDataDict = build_datatable_dict(data=tableRows, count=count, page=page, page_size=page_size)
# return build_success_response(tableDataDict)
# except frappe.ValidationError as ve:
# return build_error_response(str(ve), 400)
# except Exception as e:
# return build_error_response(str(e), 500)
addresses = [frappe.get_doc("Address", addr["name"]).as_dict() for addr in address_names]
tableRows = []
for address in addresses:
is_lead = False
tableRow = {}
links = address.links
customer_links = [link for link in links if link.link_doctype == "Customer"] if links else None
customer_name = address.get("custom_customer_to_bill", None)
if not customer_links:
customer_links = [link for link in links if link.link_doctype == "Lead"] if links else None
is_lead = True if customer_links else False
if not customer_name and not customer_links:
print("DEBUG: No customer links found and no customer to bill.")
customer_name = "N/A"
elif not customer_name and customer_links:
print("DEBUG: No customer to bill. Customer links found:", customer_links)
customer_name = frappe.get_value("Lead", customer_links[0].link_name, "lead_name") if is_lead else customer_links[0].link_name
tableRow["id"] = address["name"]
tableRow["customer_name"] = customer_name
tableRow["address"] = (
f"{address['address_line1']}"
f"{' ' + address['address_line2'] if address['address_line2'] else ''} "
f"{address['city']}, {address['state']} {address['pincode']}"
)
tableRow["appointment_scheduled_status"] = address.custom_onsite_meeting_scheduled
tableRow["estimate_sent_status"] = address.custom_estimate_sent_status
tableRow["job_status"] = address.custom_job_status
tableRow["payment_received_status"] = address.custom_payment_received_status
tableRows.append(tableRow)
tableDataDict = build_datatable_dict(data=tableRows, count=count, page=page, page_size=page_size)
return build_success_response(tableDataDict)
except frappe.ValidationError as ve:
return build_error_response(str(ve), 400)
except Exception as e:
return build_error_response(str(e), 500)
@frappe.whitelist()