50 lines
2 KiB
Python
50 lines
2 KiB
Python
import frappe, json
|
|
from custom_ui.db_utils import process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response
|
|
|
|
# ===============================================================================
|
|
# JOB MANAGEMENT API METHODS
|
|
# ===============================================================================
|
|
|
|
@frappe.whitelist()
|
|
def get_jobs_table_data(filters={}, sortings=[], page=1, page_size=10):
|
|
"""Get paginated job table data with filtering and sorting support."""
|
|
print("DEBUG: Raw job options received:", filters, sortings, page, page_size)
|
|
|
|
processed_filters, processed_sortings, is_or, page, page_size = process_query_conditions(filters, sortings, page, page_size)
|
|
|
|
# Handle count with proper OR filter support
|
|
if is_or:
|
|
count = frappe.db.sql(*get_count_or_filters("Project", processed_filters))[0][0]
|
|
else:
|
|
count = frappe.db.count("Project", filters=processed_filters)
|
|
|
|
projects = frappe.db.get_all(
|
|
"Project",
|
|
fields=["*"],
|
|
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
|
|
)
|
|
|
|
tableRows = []
|
|
for project in projects:
|
|
tableRow = {}
|
|
tableRow["id"] = project["name"]
|
|
tableRow["name"] = project["name"]
|
|
tableRow["installation_address"] = project.get("custom_installation_address", "")
|
|
tableRow["customer"] = project.get("customer", "")
|
|
tableRow["status"] = project.get("status", "")
|
|
tableRow["percent_complete"] = project.get("percent_complete", 0)
|
|
tableRows.append(tableRow)
|
|
|
|
data_table_dict = build_datatable_dict(data=tableRows, count=count, page=page, page_size=page_size)
|
|
return build_success_response(data_table_dict)
|
|
|
|
|
|
@frappe.whitelist()
|
|
def upsert_job(data):
|
|
"""Create or update a job (project)."""
|
|
# TODO: Implement job creation/update logic
|
|
pass
|