add table actions to datatable, client page, start writing db method for clients
This commit is contained in:
parent
a67e86af44
commit
df1df3f882
9 changed files with 1844 additions and 194 deletions
|
|
@ -1,6 +1,5 @@
|
|||
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):
|
||||
|
|
@ -16,13 +15,6 @@ def get_client_status_counts(weekly=False, week_start_date=None, week_end_date=N
|
|||
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 = {
|
||||
"label": "On-Site Meeting Scheduled",
|
||||
|
|
@ -58,6 +50,7 @@ def get_client_status_counts(weekly=False, week_start_date=None, week_end_date=N
|
|||
job_status_counts,
|
||||
payment_received_status_counts
|
||||
]
|
||||
|
||||
categories = []
|
||||
for status_dict in status_dicts:
|
||||
category = {
|
||||
|
|
@ -85,7 +78,28 @@ def get_client_status_counts(weekly=False, week_start_date=None, week_end_date=N
|
|||
return categories
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_clients(options):
|
||||
def get_client(client_name):
|
||||
address = frappe.get_doc("Address", client_name)
|
||||
customer_name = [link for link in address.links if link.link_doctype == "Customer"][0].link_name
|
||||
project_names = frappe.db.get_all("Project", fields=["name"], filters=[
|
||||
["or", [
|
||||
["custom_installation_address", "=", address.address_title],
|
||||
["custom_address", "=", address.address_title]
|
||||
]]
|
||||
])
|
||||
|
||||
projects = [frappe.get_doc("Project", proj["name"]) for proj in project_names]
|
||||
customer = frappe.get_doc("Customer", customer_name)
|
||||
# get all associated data as needed
|
||||
return {
|
||||
"address": address,
|
||||
"customer": customer,
|
||||
"projects": projects
|
||||
}
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_clients_table_data(options):
|
||||
options = json.loads(options)
|
||||
print("DEBUG: Raw options received:", options)
|
||||
defaultOptions = {
|
||||
|
|
@ -98,9 +112,6 @@ def get_clients(options):
|
|||
options = {**defaultOptions, **options}
|
||||
print("DEBUG: Final options:", options)
|
||||
|
||||
clients = []
|
||||
tableRows = []
|
||||
|
||||
# Map frontend field names to backend field names
|
||||
def map_field_name(frontend_field):
|
||||
field_mapping = {
|
||||
|
|
@ -162,75 +173,23 @@ def get_clients(options):
|
|||
|
||||
addresses = frappe.db.get_all(
|
||||
"Address",
|
||||
fields=["address_title", "custom_onsite_meeting_scheduled", "custom_estimate_sent_status", "custom_job_status", "custom_payment_received_status"],
|
||||
fields=["name", "address_title", "custom_onsite_meeting_scheduled", "custom_estimate_sent_status", "custom_job_status", "custom_payment_received_status"],
|
||||
filters=processed_filters,
|
||||
limit=options["page_size"],
|
||||
start=(options["page"] - 1) * options["page_size"],
|
||||
order_by=order_by
|
||||
)
|
||||
|
||||
# for address in addresses:
|
||||
# client = {}
|
||||
# tableRow = {}
|
||||
|
||||
# on_site_meetings = frappe.db.get_all(
|
||||
# "On-Site Meeting",
|
||||
# fields=["*"],
|
||||
# filters={"address": address["address_title"]}
|
||||
# )
|
||||
|
||||
# quotations = frappe.db.get_all(
|
||||
# "Quotation",
|
||||
# fields=["*"],
|
||||
# filters={"custom_installation_address": address["address_title"]}
|
||||
# )
|
||||
|
||||
# sales_orders = frappe.db.get_all(
|
||||
# "Sales Order",
|
||||
# fields=["*"],
|
||||
# filters={"custom_installation_address": address["address_title"]}
|
||||
# )
|
||||
|
||||
# sales_invvoices = frappe.db.get_all(
|
||||
# "Sales Invoice",
|
||||
# fields=["*"],
|
||||
# filters={"custom_installation_address": address["address_title"]}
|
||||
# )
|
||||
|
||||
# payment_entries = frappe.db.get_all(
|
||||
# "Payment Entry",
|
||||
# fields=["*"],
|
||||
# filters={"custom_installation_address": address["address_title"]}
|
||||
# )
|
||||
|
||||
# jobs = frappe.db.get_all(
|
||||
# "Project",
|
||||
# fields=["*"],
|
||||
# filters={
|
||||
# "custom_installation_address": address["address_title"],
|
||||
# "project_template": "SNW Install"
|
||||
# }
|
||||
# )
|
||||
|
||||
# tasks = frappe.db.get_all(
|
||||
# "Task",
|
||||
# fields=["*"],
|
||||
# filters={"project": jobs[0]["name"]}
|
||||
# ) if jobs else []
|
||||
|
||||
# tableRow["id"] = address["name"]
|
||||
# tableRow["address_title"] = address["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], payment_entries) if sales_invvoices and payment_entries else "Not Started"
|
||||
# tableRow["job_status"] = calculate_job_status(jobs[0], tasks) if jobs and tasks else "Not Started"
|
||||
# tableRows.append(tableRow)
|
||||
|
||||
# client["address"] = address
|
||||
# client["on_site_meetings"] = on_site_meetings
|
||||
# client["jobs"] = jobs
|
||||
# client["quotations"] = quotations
|
||||
# clients.append(client)
|
||||
|
||||
rows = []
|
||||
for address in addresses:
|
||||
tableRow = {}
|
||||
tableRow["id"] = address["name"]
|
||||
tableRow["address_title"] = address["address_title"]
|
||||
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"]
|
||||
rows.append(tableRow)
|
||||
|
||||
return {
|
||||
"pagination": {
|
||||
|
|
@ -239,7 +198,7 @@ def get_clients(options):
|
|||
"page_size": options["page_size"],
|
||||
"total_pages": (count + options["page_size"] - 1) // options["page_size"]
|
||||
},
|
||||
"data": addresses
|
||||
"data": rows
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue