Added price for service

This commit is contained in:
2025-08-26 17:19:52 -04:00
parent 067c9055d2
commit 9a2f9a6564
4 changed files with 72 additions and 36 deletions

View File

@@ -10,31 +10,47 @@ from app.classes.service import (Service_Service,
@service.route("/all", methods=["GET"])
def get_all_service_calls():
all_services = Service_Service.query.all()
color_map = {
0: {"backgroundColor": "blue", "textColor": "white"}, 1: {"backgroundColor": "red", "textColor": "white"},
2: {"backgroundColor": "green", "textColor": "white"}, 3: {"backgroundColor": "yellow", "textColor": "black"},
4: {"backgroundColor": "black", "textColor": "white"}
}
service_type_map = {0: 'Tune-up', 1: 'No Heat', 2: 'Fix', 3: 'Tank Install', 4: 'Other'}
calendar_events = []
for service_record in all_services:
service_type_text = service_type_map.get(service_record.type_service_call, 'Service')
event_title = f"{service_type_text}: {service_record.customer_name}"
event_colors = color_map.get(service_record.type_service_call, {"backgroundColor": "gray", "textColor": "white"})
serialized_record = Service_Service_schema().dump(service_record)
event_data = {
"id": service_record.id, "title": event_title, "start": serialized_record.get('scheduled_date'),
"end": None, "customer_id": service_record.customer_id,
"extendedProps": {
"description": service_record.description,
"type_service_call": service_record.type_service_call,
},
"backgroundColor": event_colors.get("backgroundColor"), "textColor": event_colors.get("textColor"),
"borderColor": event_colors.get("backgroundColor")
try:
all_services = Service_Service.query.all()
color_map = {
0: {"backgroundColor": "blue", "textColor": "white"}, 1: {"backgroundColor": "red", "textColor": "white"},
2: {"backgroundColor": "green", "textColor": "white"}, 3: {"backgroundColor": "yellow", "textColor": "black"},
4: {"backgroundColor": "black", "textColor": "white"}
}
calendar_events.append(event_data)
return jsonify(calendar_events), 200
service_type_map = {0: 'Tune-up', 1: 'No Heat', 2: 'Fix', 3: 'Tank Install', 4: 'Other'}
calendar_events = []
for service_record in all_services:
service_type_text = service_type_map.get(service_record.type_service_call, 'Service')
event_title = f"{service_type_text}: {service_record.customer_name}"
event_colors = color_map.get(service_record.type_service_call, {"backgroundColor": "gray", "textColor": "white"})
# Use the schema to safely get the date string
serialized_record = Service_Service_schema().dump(service_record)
start_date = serialized_record.get('scheduled_date')
event_data = {
"id": service_record.id,
"title": event_title,
"start": start_date,
"end": None,
"extendedProps": {
"customer_id": service_record.customer_id,
"description": service_record.description,
"type_service_call": service_record.type_service_call,
"service_cost": str(service_record.service_cost) if service_record.service_cost is not None else None
},
"backgroundColor": event_colors.get("backgroundColor"),
"textColor": event_colors.get("textColor"),
"borderColor": event_colors.get("backgroundColor")
}
calendar_events.append(event_data)
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}")
return jsonify(error=str(e)), 500
# --- THIS IS THE FIX ---
@@ -60,6 +76,26 @@ def get_upcoming_service_calls():
return jsonify(result), 200
@service.route("/past", methods=["GET"])
def get_past_service_calls():
"""
Fetches a list of all future service calls from today onwards.
"""
now = datetime.now()
upcoming_services = (
Service_Service.query
.filter(Service_Service.scheduled_date <= now)
.order_by(Service_Service.scheduled_date.asc())
.limit(100)
.all()
)
service_schema = Service_Service_schema(many=True)
result = service_schema.dump(upcoming_services)
return jsonify(result), 200
@service.route("/upcoming/count", methods=["GET"])
def get_upcoming_service_calls_count():
now = datetime.now()
@@ -90,7 +126,7 @@ def create_service_call():
customer_address=get_customer.customer_address, customer_town=get_customer.customer_town,
customer_state=get_customer.customer_state, customer_zip=get_customer.customer_zip,
type_service_call=data.get('type_service_call'), when_ordered=datetime.utcnow(),
scheduled_date=scheduled_datetime_obj, description=data.get('description'),
scheduled_date=scheduled_datetime_obj, description=data.get('description'), service_cost=None,
)
db.session.add(new_service_call)
db.session.commit()
@@ -106,6 +142,8 @@ def update_service_call(id):
service_record.scheduled_date = datetime.fromisoformat(scheduled_datetime_str)
service_record.type_service_call = data.get('type_service_call', service_record.type_service_call)
service_record.description = data.get('description', service_record.description)
service_record.service_cost = data.get('service_cost', service_record.service_cost)
try:
db.session.commit()
service_schema = Service_Service_schema(many=False)