From f8209e0e0a63c25e6898673620a962ad4ff04c6f Mon Sep 17 00:00:00 2001 From: ske087 Date: Sat, 6 Dec 2025 23:29:23 +0200 Subject: [PATCH] updated to fix create location page --- py_app/app/routes.py | 1 + py_app/app/warehouse.py | 46 +++++++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/py_app/app/routes.py b/py_app/app/routes.py index 3e135b1..20102d9 100755 --- a/py_app/app/routes.py +++ b/py_app/app/routes.py @@ -3878,6 +3878,7 @@ def mark_printed(): return jsonify({'error': str(e)}), 500 @warehouse_bp.route('/create_locations', methods=['GET', 'POST']) +@requires_warehouse_module def create_locations(): from app.warehouse import create_locations_handler return create_locations_handler() diff --git a/py_app/app/warehouse.py b/py_app/app/warehouse.py index 763b7db..cf5883b 100755 --- a/py_app/app/warehouse.py +++ b/py_app/app/warehouse.py @@ -99,24 +99,34 @@ def delete_locations_by_ids(ids_str): return f"Deleted {deleted} location(s)." def create_locations_handler(): - if request.method == "POST": - if request.form.get("delete_locations"): - ids_str = request.form.get("delete_ids", "") - message = delete_locations_by_ids(ids_str) - session['flash_message'] = message - else: - location_code = request.form.get("location_code") - size = request.form.get("size") - description = request.form.get("description") - message = add_location(location_code, size, description) - session['flash_message'] = message - # Redirect to prevent form resubmission on page reload - return redirect(url_for('warehouse.create_locations')) - - # Get flash message from session if any - message = session.pop('flash_message', None) - locations = get_locations() - return render_template("create_locations.html", locations=locations, message=message) + try: + # Ensure table exists + ensure_warehouse_locations_table() + + if request.method == "POST": + if request.form.get("delete_locations"): + ids_str = request.form.get("delete_ids", "") + message = delete_locations_by_ids(ids_str) + session['flash_message'] = message + else: + location_code = request.form.get("location_code") + size = request.form.get("size") + description = request.form.get("description") + message = add_location(location_code, size, description) + session['flash_message'] = message + # Redirect to prevent form resubmission on page reload + return redirect(url_for('warehouse.create_locations')) + + # Get flash message from session if any + message = session.pop('flash_message', None) + locations = get_locations() + return render_template("create_locations.html", locations=locations, message=message) + except Exception as e: + import traceback + error_trace = traceback.format_exc() + print(f"Error in create_locations_handler: {e}") + print(error_trace) + return f"

Error loading warehouse locations

{error_trace}
", 500 def import_locations_csv_handler(): report = None