major claude changes

This commit is contained in:
2026-01-28 21:55:10 -05:00
parent 3f311980db
commit 2dbd3ea53f
41 changed files with 1235 additions and 278 deletions

View File

@@ -1,3 +1,4 @@
import logging
from flask import request, jsonify
from app.service import service
from app import db
@@ -8,9 +9,14 @@ from app.classes.service import (Service_Service,
Service_Plans, Service_Plans_schema
)
from app.classes.auto import Auto_Delivery
from flask_login import login_required
logger = logging.getLogger(__name__)
@service.route("/all", methods=["GET"])
@login_required
def get_all_service_calls():
logger.info("GET /service/all - Fetching all service calls for calendar")
try:
all_services = Service_Service.query.all()
color_map = {
@@ -49,18 +55,19 @@ def get_all_service_calls():
return jsonify(calendar_events), 200
except Exception as e:
# Add error logging to see what's happening
print(f"An error occurred in /service/all: {e}")
logger.error(f"Error in /service/all: {e}")
return jsonify(error=str(e)), 500
# --- THIS IS THE FIX ---
# The logic from /all has been copied here to ensure a consistent data structure.
@service.route("/upcoming", methods=["GET"])
@login_required
def get_upcoming_service_calls():
"""
Fetches a list of all future service calls from today onwards.
"""
logger.info("GET /service/upcoming - Fetching upcoming service calls")
now = datetime.now()
upcoming_services = (
Service_Service.query
@@ -78,6 +85,7 @@ def get_upcoming_service_calls():
@service.route("/past", methods=["GET"])
@login_required
def get_past_service_calls():
"""
Fetches a list of all past service calls before today.
@@ -97,6 +105,7 @@ def get_past_service_calls():
@service.route("/today", methods=["GET"])
@login_required
def get_today_service_calls():
"""
Fetches a list of all service calls for today.
@@ -119,6 +128,7 @@ def get_today_service_calls():
@service.route("/upcoming/count", methods=["GET"])
@login_required
def get_upcoming_service_calls_count():
now = datetime.now()
try:
@@ -128,6 +138,7 @@ def get_upcoming_service_calls_count():
return jsonify({"error": str(e)}), 500
@service.route("/for-customer/<int:customer_id>", methods=["GET"])
@login_required
def get_service_calls_for_customer(customer_id):
service_records = (Service_Service.query.filter_by(customer_id=customer_id).order_by(Service_Service.scheduled_date.desc()).all())
service_schema = Service_Service_schema(many=True)
@@ -135,6 +146,7 @@ def get_service_calls_for_customer(customer_id):
return jsonify(result), 200
@service.route("/create", methods=["POST"])
@login_required
def create_service_call():
data = request.get_json()
if not data: return jsonify({"error": "No data provided"}), 400
@@ -155,6 +167,7 @@ def create_service_call():
return jsonify({ "ok": True, "id": new_service_call.id }), 201
@service.route("/update-cost/<int:id>", methods=["PUT"])
@login_required
def update_service_cost(id):
"""
Dedicated endpoint to update only the service cost for a service call.
@@ -196,10 +209,11 @@ def update_service_cost(id):
except Exception as e:
db.session.rollback()
print(f"Error updating service cost for service {id}: {str(e)}")
logger.error(f"Error updating service cost for service {id}: {e}")
return jsonify({"error": str(e)}), 500
@service.route("/update/<int:id>", methods=["PUT"])
@login_required
def update_service_call(id):
service_record = Service_Service.query.get_or_404(id)
data = request.get_json()
@@ -222,6 +236,7 @@ def update_service_call(id):
# Service Plans CRUD endpoints
@service.route("/plans/active", methods=["GET"])
@login_required
def get_active_service_plans():
"""
Get all active service plans (contract_plan > 0)
@@ -245,6 +260,7 @@ def get_active_service_plans():
@service.route("/plans/customer/<int:customer_id>", methods=["GET"])
@login_required
def get_customer_service_plan(customer_id):
"""
Get service plan for a specific customer
@@ -261,6 +277,7 @@ def get_customer_service_plan(customer_id):
@service.route("/plans/create", methods=["POST"])
@login_required
def create_service_plan():
"""
Create a new service plan for a customer
@@ -287,6 +304,7 @@ def create_service_plan():
@service.route("/plans/update/<int:customer_id>", methods=["PUT"])
@login_required
def update_service_plan(customer_id):
"""
Update existing service plan for a customer
@@ -317,6 +335,7 @@ def update_service_plan(customer_id):
@service.route("/plans/delete/<int:customer_id>", methods=["DELETE"])
@login_required
def delete_service_plan(customer_id):
"""
Delete service plan for a customer
@@ -334,12 +353,14 @@ def delete_service_plan(customer_id):
return jsonify({"error": str(e)}), 500
@service.route("/<int:id>", methods=["GET"])
@login_required
def get_service_by_id(id):
service_record = Service_Service.query.get_or_404(id)
service_schema = Service_Service_schema()
return jsonify({"ok": True, "service": service_schema.dump(service_record)}), 200
@service.route("/delete/<int:id>", methods=["DELETE"])
@login_required
def delete_service_call(id):
service_record = Service_Service.query.get_or_404(id)
try:
@@ -351,6 +372,7 @@ def delete_service_call(id):
return jsonify({"error": str(e)}), 500
@service.route("/parts/customer/<int:customer_id>", methods=["GET"])
@login_required
def get_service_parts(customer_id):
parts = Service_Parts.query.filter_by(customer_id=customer_id).first()
if parts:
@@ -363,6 +385,7 @@ def get_service_parts(customer_id):
}), 200
@service.route("/parts/update/<int:customer_id>", methods=["POST"])
@login_required
def update_service_parts(customer_id):
try:
data = request.get_json()
@@ -397,6 +420,7 @@ def update_service_parts(customer_id):
@service.route("/payment/<int:service_id>/<int:payment_type>", methods=["PUT"])
@login_required
def process_service_payment(service_id, payment_type):
service = db.session.query(Service_Service).filter(Service_Service.id == service_id).first()
if not service: