massage data

This commit is contained in:
Casey 2025-11-06 18:24:19 -06:00
parent 616fa1be79
commit 60d3f35988
7 changed files with 174 additions and 48 deletions

View file

@ -1,4 +1,5 @@
import frappe, json
from custom_ui.db_utils import calculate_appointment_scheduled_status, calculate_estimate_sent_status, calculate_payment_recieved_status, calculate_job_scheduled_status
@frappe.whitelist()
def get_clients(options):
@ -8,11 +9,13 @@ def get_clients(options):
"filters": {},
"sorting": {},
"page": 1,
"page_size": 10
"page_size": 10,
"for_table": False
}
options = {**defaultOptions, **options}
clients = []
tableRows = []
count = frappe.db.count("Address", filters=options["filters"])
print("DEBUG: Total addresses count:", count)
@ -28,29 +31,58 @@ def get_clients(options):
for address in addresses:
client = {}
tableRow = {}
print("DEBUG: Processing address:", address)
on_site_meetings = frappe.db.get_all(
"On-Site Meeting",
fields=["*"],
filters={"address": address["address_title"]}
)
sales_invvoices = frappe.db.get_all(
"Sales Invoice",
fields=["*"],
filters={"custom_installation_address": address["address_title"]}
)
quotations = frappe.db.get_all(
"Quotation",
fields=["*"],
filters={"custom_installation_address": address["name"]}
filters={"custom_installation_address": address["address_title"]}
)
jobs = frappe.db.get_all("Project",
fields=["*"],
filters={"custom_installation_address": address["name"],
"project_template": "SNW Install"})
jobs = frappe.db.get_all(
"Project",
fields=["*"],
filters={
"custom_installation_address": address["address_title"],
"project_template": "SNW Install"
}
)
tableRow["id"] = address["name"]
tableRow["address_name"] = address.get("address_title", "")
tableRow["appointment_scheduled_status"] = calculate_appointment_scheduled_status(on_site_meetings[0]) if on_site_meetings else "Not Started"
tableRow["estimate_sent_status"] = calculate_estimate_sent_status(quotations[0]) if quotations else "Not Started"
tableRow["payment_received_status"] = calculate_payment_recieved_status(sales_invvoices[0]) if sales_invvoices else "Not Started"
tableRow["job_scheduled_status"] = calculate_job_scheduled_status(jobs[0]) if jobs else "Not Started"
tableRows.append(tableRow)
client["address"] = address
client["on_site_meetings"] = []
client["on_site_meetings"] = on_site_meetings
client["jobs"] = jobs
client["quotations"] = quotations
clients.append(client)
return {
"count": count,
"page": options["page"],
"page_size": options["page_size"],
"clients": clients
"pagination": {
"total": count,
"page": options["page"],
"page_size": options["page_size"],
"total_pages": (count + options["page_size"] - 1) // options["page_size"]
},
"data": tableRows if options["for_table"] else clients
}
@frappe.whitelist()

28
custom_ui/db_utils.py Normal file
View file

@ -0,0 +1,28 @@
def calculate_appointment_scheduled_status(on_site_meeting):
if not on_site_meeting:
return "Not Started"
# if on_site_meeting["end_time"] < today:
# return "In Progress"
return "Completed"
def calculate_estimate_sent_status(quotation):
if not quotation:
return "Not Started"
if quotation["custom_sent"] == 1:
return "Completed"
return "In Progress"
def calculate_payment_recieved_status(sales_invoice):
if not sales_invoice:
return "Not Started"
if sales_invoice and sales_invoice["status"] == "Paid":
return "Completed"
return "In Progress"
def calculate_job_scheduled_status(project):
if not project:
return "Not Started"
if not project["start_time"]:
return "In Progress"
return "Completed"