add whitlist metho for getting status counts

This commit is contained in:
Casey Wittrock 2025-11-07 15:46:07 -06:00
parent 84bdff4613
commit 3ea47162c5
2 changed files with 77 additions and 153 deletions

View file

@ -2,6 +2,71 @@ import frappe, json, re
from datetime import datetime, date
from custom_ui.db_utils import calculate_appointment_scheduled_status, calculate_estimate_sent_status, calculate_payment_recieved_status, calculate_job_status
@frappe.whitelist()
def get_client_status_counts(weekly=False, week_start_date=None, week_end_date=None):
# Build base filters for date range if weekly filtering is enabled
base_filters = {}
if weekly and week_start_date and week_end_date:
# Assuming you have a date field to filter by - adjust the field name as needed
# Common options: creation, modified, custom_date_field, etc.
base_filters["creation"] = ["between", [week_start_date, week_end_date]]
# Helper function to merge base filters with status filters
def get_filters(status_field, status_value):
filters = {status_field: status_value}
filters.update(base_filters)
return filters
def get_status_total(counts_dicts, status_field):
sum_array = []
for counts_dict in counts_dicts:
sum_array.append(counts_dict[status_field])
return sum(sum_array)
onsite_meeting_scheduled_status_counts = {
"Not Started": frappe.db.count("Address", filters=get_filters("custom_onsite_meeting_scheduled_status", "Not Started")),
"In Progress": frappe.db.count("Address", filters=get_filters("custom_onsite_meeting_scheduled_status", "In Progress")),
"Completed": frappe.db.count("Address", filters=get_filters("custom_onsite_meeting_scheduled_status", "Completed"))
}
estimate_sent_status_counts = {
"Not Started": frappe.db.count("Address", filters=get_filters("custom_estimate_sent_status", "Not Started")),
"In Progress": frappe.db.count("Address", filters=get_filters("custom_estimate_sent_status", "In Progress")),
"Completed": frappe.db.count("Address", filters=get_filters("custom_estimate_sent_status", "Completed"))
}
job_status_counts = {
"Not Started": frappe.db.count("Address", filters=get_filters("custom_job_status", "Not Started")),
"In Progress": frappe.db.count("Address", filters=get_filters("custom_job_status", "In Progress")),
"Completed": frappe.db.count("Address", filters=get_filters("custom_job_status", "Completed"))
}
payment_received_status_counts = {
"Not Started": frappe.db.count("Address", filters=get_filters("custom_payment_received_status", "Not Started")),
"In Progress": frappe.db.count("Address", filters=get_filters("custom_payment_received_status", "In Progress")),
"Completed": frappe.db.count("Address", filters=get_filters("custom_payment_received_status", "Completed"))
}
status_dicts = [
onsite_meeting_scheduled_status_counts,
estimate_sent_status_counts,
job_status_counts,
payment_received_status_counts
]
return {
"totals": {
"not_started": get_status_total(status_dicts, "Not Started"),
"in_progress": get_status_total(status_dicts, "In Progress"),
"completed": get_status_total(status_dicts, "Completed")
},
"onsite_meeting_scheduled_status": onsite_meeting_scheduled_status_counts,
"estimate_sent_status": estimate_sent_status_counts,
"job_status": job_status_counts,
"payment_received_status": payment_received_status_counts
}
@frappe.whitelist()
def get_clients(options):
options = json.loads(options)