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

@@ -120,42 +120,42 @@ def teardown_appcontext(error):
@app.errorhandler(500)
def internal_error500():
def internal_error500(error):
return jsonify({"error": "Internal Error 500"}), 500
@app.errorhandler(502)
def internal_error502():
def internal_error502(error):
return jsonify({"error": "Internal Error 502"}), 502
@app.errorhandler(404)
def internal_error404():
def internal_error404(error):
return jsonify({"error": "Internal Error 400"}), 400
@app.errorhandler(401)
def internal_error404():
def internal_error401(error):
return jsonify({"error": "Internal Error 401"}), 401
@app.errorhandler(400)
def internal_error400():
def internal_error400(error):
return jsonify({"error": "Internal Error 400"}), 400
@app.errorhandler(413)
def to_large_file():
def to_large_file(error):
return jsonify({"error": "File is too large. Use a smaller image/file."}), 413
@app.errorhandler(403)
def internal_error403():
def internal_error403(error):
return jsonify({"error": "Internal Error 403"}), 403
@app.errorhandler(405)
def internal_error():
def internal_error(error):
return jsonify({"error": "Internal Error 405"}), 405

View File

@@ -28,7 +28,7 @@ class Service_Service(db.Model):
scheduled_date = db.Column(db.DATETIME())
description = db.Column(db.TEXT())
service_cost = db.Column(db.Numeric(10, 2), nullable=False)
class Service_Service_schema(ma.SQLAlchemyAutoSchema):

View File

@@ -25,14 +25,12 @@ def get_pricing_tiers():
gallon_tiers = [100, 125, 150, 175, 200, 220]
# Calculate the total price for each gallon amount by multiplication
# e.g., { 100: (2.92 * 100), 125: (2.92 * 125), ... }
pricing_totals = {
gallons: price_per_gallon * gallons
for gallons in gallon_tiers
}
# Return the dictionary of totals
# e.g., { "100": "292.00", "125": "365.00", ... }
return jsonify(pricing_totals)
@info.route("/price/oil", methods=["GET"])

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)