Files
quality_app-v2/app/modules/warehouse/routes.py
Quality App Developer b15cc93b9d FG Scan form validation improvements with warehouse module updates
- Fixed 3 JavaScript syntax errors in fg_scan.html (lines 951, 840-950, 1175-1215)
- Restored form field validation with proper null safety checks
- Re-enabled auto-advance between form fields
- Re-enabled CP code auto-complete with hyphen detection
- Updated validation error messages with clear format specifications and examples
- Added autocomplete='off' to all input fields
- Removed auto-prefix correction feature
- Updated warehouse routes and modules for box assignment workflow
- Added/improved database initialization scripts
- Updated requirements.txt dependencies

Format specifications implemented:
- Operator Code: OP + 2 digits (example: OP01, OP99)
- CP Code: CP + 8 digits + hyphen + 4 digits (example: CP00000000-0001)
- OC1/OC2 Codes: OC + 2 digits (example: OC01, OC99)
- Defect Code: 3 digits only
2026-01-30 10:50:06 +02:00

218 lines
8.1 KiB
Python

"""
Warehouse Module Routes
"""
from flask import Blueprint, render_template, session, redirect, url_for, request, flash, jsonify
from app.modules.warehouse.warehouse import (
get_all_locations, add_location, update_location, delete_location,
delete_multiple_locations, get_location_by_id,
search_box_by_number, search_location_with_boxes,
assign_box_to_location, move_box_to_new_location
)
import logging
logger = logging.getLogger(__name__)
warehouse_bp = Blueprint('warehouse', __name__, url_prefix='/warehouse')
@warehouse_bp.route('/', methods=['GET'])
def warehouse_index():
"""Warehouse module main page - launcher for all warehouse operations"""
if 'user_id' not in session:
return redirect(url_for('main.login'))
return render_template('modules/warehouse/index.html')
@warehouse_bp.route('/set-boxes-locations', methods=['GET', 'POST'])
def set_boxes_locations():
"""Set boxes locations - add or update articles in warehouse inventory"""
if 'user_id' not in session:
return redirect(url_for('main.login'))
return render_template('modules/warehouse/set_boxes_locations.html')
@warehouse_bp.route('/locations', methods=['GET', 'POST'])
def locations():
"""Create and manage warehouse locations"""
if 'user_id' not in session:
return redirect(url_for('main.login'))
message = None
message_type = 'info'
if request.method == 'POST':
# Handle edit location
if request.form.get('edit_location'):
location_id = request.form.get('location_id', '')
size = request.form.get('edit_size', '').strip()
description = request.form.get('edit_description', '').strip()
try:
location_id = int(location_id)
success, msg = update_location(location_id, None, size if size else None, description if description else None)
message = msg
message_type = 'success' if success else 'error'
except Exception as e:
message = f"Error: {str(e)}"
message_type = 'error'
# Handle delete locations
elif request.form.get('delete_locations'):
delete_ids_str = request.form.get('delete_ids', '')
try:
location_ids = [int(id.strip()) for id in delete_ids_str.split(',') if id.strip().isdigit()]
success, msg = delete_multiple_locations(location_ids)
message = msg
message_type = 'success' if success else 'error'
except Exception as e:
message = f"Error: {str(e)}"
message_type = 'error'
# Handle add location
elif request.form.get('add_location'):
location_code = request.form.get('location_code', '').strip()
size = request.form.get('size', '').strip()
description = request.form.get('description', '').strip()
if not location_code:
message = "Location code is required"
message_type = 'error'
else:
success, msg = add_location(location_code, size if size else None, description if description else None)
message = msg
message_type = 'success' if success else 'error'
# Get all locations
locations_list = get_all_locations()
return render_template('modules/warehouse/locations.html',
locations=locations_list,
message=message,
message_type=message_type)
@warehouse_bp.route('/boxes', methods=['GET', 'POST'])
def boxes():
"""Manage boxes and crates in the warehouse"""
if 'user_id' not in session:
return redirect(url_for('main.login'))
return render_template('modules/warehouse/boxes.html')
@warehouse_bp.route('/inventory', methods=['GET'])
def inventory():
"""View warehouse inventory - products, boxes, and locations"""
if 'user_id' not in session:
return redirect(url_for('main.login'))
return render_template('modules/warehouse/inventory.html')
@warehouse_bp.route('/reports', methods=['GET'])
def reports():
"""Warehouse activity and inventory reports"""
if 'user_id' not in session:
return redirect(url_for('main.login'))
return render_template('modules/warehouse/reports.html')
@warehouse_bp.route('/test-barcode', methods=['GET'])
def test_barcode():
"""Test barcode printing functionality"""
if 'user_id' not in session:
return redirect(url_for('main.login'))
return render_template('modules/warehouse/test_barcode.html')
# ============================================================================
# API Routes for Set Boxes Locations Feature
# ============================================================================
@warehouse_bp.route('/api/search-box', methods=['POST'], endpoint='api_search_box')
def api_search_box():
"""Search for a box by number"""
if 'user_id' not in session:
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
data = request.get_json()
box_number = data.get('box_number', '').strip()
if not box_number:
return jsonify({'success': False, 'error': 'Box number is required'}), 400
success, box_data, status_code = search_box_by_number(box_number)
if success:
return jsonify({'success': True, 'box': box_data}), 200
else:
return jsonify({'success': False, 'error': f'Box "{box_number}" not found'}), status_code
@warehouse_bp.route('/api/search-location', methods=['POST'], endpoint='api_search_location')
def api_search_location():
"""Search for a location and get all boxes in it"""
if 'user_id' not in session:
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
data = request.get_json()
location_code = data.get('location_code', '').strip()
if not location_code:
return jsonify({'success': False, 'error': 'Location code is required'}), 400
success, response_data, status_code = search_location_with_boxes(location_code)
if success:
return jsonify({'success': True, **response_data}), 200
else:
return jsonify({'success': False, 'error': response_data.get('error', 'Not found')}), status_code
@warehouse_bp.route('/api/assign-box-to-location', methods=['POST'], endpoint='api_assign_box_to_location')
def api_assign_box_to_location():
"""Assign a box to a location"""
if 'user_id' not in session:
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
data = request.get_json()
box_id = data.get('box_id')
location_code = data.get('location_code', '').strip()
if not box_id or not location_code:
return jsonify({'success': False, 'error': 'Box ID and location code are required'}), 400
success, message, status_code = assign_box_to_location(box_id, location_code)
return jsonify({'success': success, 'message': message}), status_code
@warehouse_bp.route('/api/move-box-to-location', methods=['POST'], endpoint='api_move_box_to_location')
def api_move_box_to_location():
"""Move a box to a new location"""
if 'user_id' not in session:
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
data = request.get_json()
box_id = data.get('box_id')
new_location_code = data.get('new_location_code', '').strip()
if not box_id or not new_location_code:
return jsonify({'success': False, 'error': 'Box ID and new location code are required'}), 400
success, message, status_code = move_box_to_new_location(box_id, new_location_code)
return jsonify({'success': success, 'message': message}), status_code
@warehouse_bp.route('/api/get-locations', methods=['GET'], endpoint='api_get_locations')
def api_get_locations():
"""Get all warehouse locations for dropdown"""
if 'user_id' not in session:
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
locations = get_all_locations()
return jsonify({'success': True, 'locations': locations}), 200