Added Job detail page with a datatable displaying all Tasks related to that Job.
This commit is contained in:
parent
49840b6c38
commit
b2f77f2ca1
3 changed files with 219 additions and 22 deletions
|
|
@ -1,10 +1,69 @@
|
|||
import frappe, json
|
||||
from custom_ui.db_utils import process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response
|
||||
from custom_ui.db_utils import process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response, build_error_response
|
||||
|
||||
# ===============================================================================
|
||||
# JOB MANAGEMENT API METHODS
|
||||
# ===============================================================================
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_job(job_id=""):
|
||||
"""Get particular Job from DB"""
|
||||
print("DEBUG: Loading Job from database:", job_id)
|
||||
try:
|
||||
project = frappe.get_doc("Project", job_id)
|
||||
return build_success_response(project)
|
||||
except Exception as e:
|
||||
return build_error_response(str(e), 500)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_job_task_table_data(filters={}, sortings={}, page=1, page_size=10):
|
||||
"""Get paginated job tasks table data with filtering and sorting support."""
|
||||
print("DEBUG: raw task options received:", filters, sortings, page, page_size)
|
||||
|
||||
processed_filters, processed_sortings, is_or, page, page_size = process_query_conditions(filters, sortings, page, page_size)
|
||||
|
||||
if is_or:
|
||||
count = frappe.db.sql(*get_count_or_filters("Task", processed_filters))[0][0]
|
||||
else:
|
||||
count = frappe.db.count("Task", filters=processed_filters)
|
||||
|
||||
print(f"DEBUG: Number of tasks returned: {count}")
|
||||
|
||||
tasks = frappe.db.get_all(
|
||||
"Task",
|
||||
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 task in tasks:
|
||||
tableRow = {}
|
||||
tableRow["name"] = task["name"]
|
||||
tableRow["subject"] = task["subject"]
|
||||
tableRow["address"] = task.get("custom_property", "")
|
||||
tableRow["status"] = task.get("status", "")
|
||||
tableRows.append(tableRow)
|
||||
|
||||
table_data_dict = build_datatable_dict(data=tableRows, count=count, page=page, page_size=page_size)
|
||||
return build_success_response(table_data_dict)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_job_task_list(job_id=""):
|
||||
if job_id:
|
||||
try:
|
||||
tasks = frappe.get_all('Task', filters={"project": job_id})
|
||||
task_docs = {task_id: frappe.get_doc(task_id) for task_id in tasks}
|
||||
return build_success_response(task_docs)
|
||||
except Exception as e:
|
||||
return build_error_response(str(e), 500)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_jobs_table_data(filters={}, sortings=[], page=1, page_size=10):
|
||||
"""Get paginated job table data with filtering and sorting support."""
|
||||
|
|
@ -49,19 +108,19 @@ def upsert_job(data):
|
|||
try:
|
||||
if isinstance(data, str):
|
||||
data = json.loads(data)
|
||||
|
||||
|
||||
project_id = data.get("id")
|
||||
if not project_id:
|
||||
return {"status": "error", "message": "Project ID is required"}
|
||||
|
||||
|
||||
project = frappe.get_doc("Project", project_id)
|
||||
|
||||
|
||||
if "scheduledDate" in data:
|
||||
project.expected_start_date = data["scheduledDate"]
|
||||
|
||||
|
||||
if "foreman" in data:
|
||||
project.custom_install_crew = data["foreman"]
|
||||
|
||||
|
||||
project.save()
|
||||
return {"status": "success", "data": project.as_dict()}
|
||||
except Exception as e:
|
||||
|
|
@ -75,16 +134,16 @@ def get_install_projects(start_date=None, end_date=None):
|
|||
# If date range provided, we could filter, but for now let's fetch all open/active ones
|
||||
# or maybe filter by status not Closed/Completed if we want active ones.
|
||||
# The user said "unscheduled" are those with status "Open" (and no date).
|
||||
|
||||
|
||||
projects = frappe.get_all("Project", fields=["*"], filters=filters)
|
||||
|
||||
|
||||
calendar_events = []
|
||||
for project in projects:
|
||||
# Determine status
|
||||
status = "unscheduled"
|
||||
if project.get("expected_start_date"):
|
||||
status = "scheduled"
|
||||
|
||||
|
||||
# Map to calendar event format
|
||||
event = {
|
||||
"id": project.name,
|
||||
|
|
@ -101,9 +160,9 @@ def get_install_projects(start_date=None, end_date=None):
|
|||
"notes": project.notes,
|
||||
"address": project.custom_installation_address
|
||||
}
|
||||
|
||||
|
||||
calendar_events.append(event)
|
||||
|
||||
|
||||
return {"status": "success", "data": calendar_events}
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": str(e)}
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue