Working time
This commit is contained in:
@@ -66,42 +66,51 @@ def get_upcoming_service_calls():
|
|||||||
result = service_schema.dump(upcoming_services)
|
result = service_schema.dump(upcoming_services)
|
||||||
return jsonify(result), 200
|
return jsonify(result), 200
|
||||||
|
|
||||||
|
@service.route("/create", methods=["POST"])
|
||||||
|
def create_service_call():
|
||||||
|
data = request.get_json()
|
||||||
|
if not data: return jsonify({"error": "No data provided"}), 400
|
||||||
|
|
||||||
|
cus_id=data.get('customer_id')
|
||||||
|
get_customer = (db.session.query(Customer_Customer).filter(Customer_Customer.id == cus_id).first())
|
||||||
|
if not get_customer: return jsonify({"error": f"Customer with id {cus_id} not found."}), 404
|
||||||
|
|
||||||
|
# --- FIX: Use fromisoformat to parse the FULL timestamp string (e.g., "2025-08-26T14:00:00") ---
|
||||||
|
# This correctly preserves the time sent from the frontend.
|
||||||
|
scheduled_datetime_str = data.get('expected_delivery_date')
|
||||||
|
scheduled_datetime_obj = datetime.fromisoformat(scheduled_datetime_str)
|
||||||
|
|
||||||
|
new_service_call = Service_Service(
|
||||||
|
customer_id=get_customer.id, customer_name=get_customer.customer_first_name + ' ' + get_customer.customer_last_name,
|
||||||
|
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, # Save the full datetime object
|
||||||
|
description=data.get('description'),
|
||||||
|
)
|
||||||
|
db.session.add(new_service_call)
|
||||||
|
db.session.commit()
|
||||||
|
return jsonify({ "ok": True, "id": new_service_call.id }), 201
|
||||||
|
|
||||||
|
|
||||||
@service.route("/update/<int:id>", methods=["PUT"])
|
@service.route("/update/<int:id>", methods=["PUT"])
|
||||||
def update_service_call(id):
|
def update_service_call(id):
|
||||||
# ... (no changes)
|
|
||||||
service_record = Service_Service.query.get_or_404(id)
|
service_record = Service_Service.query.get_or_404(id)
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
if not data: return jsonify({"error": "No data provided"}), 400
|
if not data: return jsonify({"error": "No data provided"}), 400
|
||||||
scheduled_date_str = data.get('scheduled_date')
|
|
||||||
if scheduled_date_str: service_record.scheduled_date = datetime.strptime(scheduled_date_str, '%Y-%m-%d')
|
# --- FIX: Also use fromisoformat here to correctly update with time ---
|
||||||
|
scheduled_datetime_str = data.get('scheduled_date')
|
||||||
|
if scheduled_datetime_str:
|
||||||
|
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.type_service_call = data.get('type_service_call', service_record.type_service_call)
|
||||||
service_record.description = data.get('description', service_record.description)
|
service_record.description = data.get('description', service_record.description)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
service_schema = Service_Service_schema(many=False)
|
service_schema = Service_Service_schema(many=False)
|
||||||
return jsonify({"ok": True, "service": service_schema.dump(service_record)}), 200
|
return jsonify({"ok": True, "service": service_schema.dump(service_record)}), 200
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
return jsonify({"error": str(e)}), 500
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
@service.route("/create", methods=["POST"])
|
|
||||||
def create_service_call():
|
|
||||||
# ... (no changes)
|
|
||||||
data = request.get_json()
|
|
||||||
cus_id=data.get('customer_id')
|
|
||||||
get_customer = (db.session.query(Customer_Customer).filter(Customer_Customer.id == cus_id).first())
|
|
||||||
if not get_customer: return jsonify({"error": f"Customer with id {cus_id} not found."}), 404
|
|
||||||
scheduled_date_str = data.get('expected_delivery_date').split('T')[0]
|
|
||||||
scheduled_date_obj = datetime.strptime(scheduled_date_str, '%Y-%m-%d')
|
|
||||||
new_service_call = Service_Service(
|
|
||||||
customer_id=get_customer.id, customer_name=get_customer.customer_first_name + ' ' + get_customer.customer_last_name,
|
|
||||||
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_date_obj, description=data.get('description'),
|
|
||||||
)
|
|
||||||
db.session.add(new_service_call)
|
|
||||||
db.session.commit()
|
|
||||||
return jsonify({ "ok": True, "id": new_service_call.id }), 201
|
|
||||||
|
|
||||||
# ... (and so on for your other routes) ...
|
|
||||||
Reference in New Issue
Block a user