install calendar

This commit is contained in:
Casey 2025-12-23 08:58:33 -06:00
parent 410671c397
commit 9de586cf3c
4 changed files with 1275 additions and 3 deletions

View file

@ -46,5 +46,64 @@ def get_jobs_table_data(filters={}, sortings=[], page=1, page_size=10):
@frappe.whitelist()
def upsert_job(data):
"""Create or update a job (project)."""
# TODO: Implement job creation/update logic
pass
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:
return {"status": "error", "message": str(e)}
@frappe.whitelist()
def get_install_projects(start_date=None, end_date=None):
"""Get install projects for the calendar."""
try:
filters = {"project_template": "SNW Install"}
# 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,
"serviceType": project.project_name, # Using project name as service type/title
"customer": project.customer,
"status": status,
"scheduledDate": project.expected_start_date,
"scheduledTime": "08:00", # Default time if not specified? Project doesn't seem to have time.
"duration": 480, # Default 8 hours?
"foreman": project.get("custom_install_crew"),
"crew": [], # Need to map crew
"estimatedCost": project.estimated_costing,
"priority": project.priority.lower() if project.priority else "medium",
"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)}