feat: Add Set Orders on Boxes feature with debouncing and page refresh

- Created warehouse_orders.py module with 8 order management functions
- Added /warehouse/set-orders-on-boxes route and 7 API endpoints
- Implemented 4-tab interface: assign, find, move, and view orders
- Changed assign input from dropdown to text field with BOX validation
- Fixed location join issue in warehouse.py (use boxes_crates.location_id)
- Added debouncing flag to prevent multiple rapid form submissions
- Added page refresh after successful order assignment
- Disabled assign button during processing
- Added page refresh with 2 second delay for UX feedback
- Added CP code validation in inventory page
- Improved modal styling with theme support
- Fixed set_boxes_locations page to refresh box info after assignments
This commit is contained in:
Quality App Developer
2026-02-02 01:06:03 +02:00
parent 39a3a0084c
commit f54e1bebc3
7 changed files with 1986 additions and 52 deletions

View File

@@ -9,6 +9,11 @@ from app.modules.warehouse.warehouse import (
assign_box_to_location, move_box_to_new_location,
get_cp_inventory_list, search_cp_code, search_by_box_number, get_cp_details
)
from app.modules.warehouse.warehouse_orders import (
get_unassigned_orders, get_orders_by_box, search_orders_by_cp_code,
assign_order_to_box, move_order_to_box, unassign_order_from_box,
get_all_boxes_summary
)
import logging
logger = logging.getLogger(__name__)
@@ -119,6 +124,15 @@ def reports():
return render_template('modules/warehouse/reports.html')
@warehouse_bp.route('/set-orders-on-boxes', methods=['GET', 'POST'])
def set_orders_on_boxes():
"""Set orders on boxes - assign or move orders between boxes"""
if 'user_id' not in session:
return redirect(url_for('main.login'))
return render_template('modules/warehouse/set_orders_on_boxes.html')
@warehouse_bp.route('/test-barcode', methods=['GET'])
def test_barcode():
"""Test barcode printing functionality"""
@@ -218,6 +232,119 @@ def api_get_locations():
return jsonify({'success': True, 'locations': locations}), 200
# ============================================================================
# API Routes for Orders Management
# ============================================================================
@warehouse_bp.route('/api/unassigned-orders', methods=['GET'], endpoint='api_unassigned_orders')
def api_unassigned_orders():
"""Get all unassigned orders"""
if 'user_id' not in session:
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
try:
limit = request.args.get('limit', 100, type=int)
offset = request.args.get('offset', 0, type=int)
orders = get_unassigned_orders(limit, offset)
return jsonify({'success': True, 'orders': orders, 'count': len(orders)}), 200
except Exception as e:
logger.error(f"Error getting unassigned orders: {e}")
return jsonify({'success': False, 'error': str(e)}), 500
@warehouse_bp.route('/api/orders-by-box', methods=['POST'], endpoint='api_orders_by_box')
def api_orders_by_box():
"""Get all orders assigned to a specific box"""
if 'user_id' not in session:
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
data = request.get_json()
box_id = data.get('box_id')
if not box_id:
return jsonify({'success': False, 'error': 'Box ID is required'}), 400
success, data_resp, status_code = get_orders_by_box(box_id)
return jsonify({'success': success, **data_resp}), status_code
@warehouse_bp.route('/api/search-orders', methods=['POST'], endpoint='api_search_orders')
def api_search_orders():
"""Search for orders by CP code"""
if 'user_id' not in session:
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
data = request.get_json()
cp_code = data.get('cp_code', '').strip()
if not cp_code:
return jsonify({'success': False, 'error': 'CP code is required'}), 400
orders = search_orders_by_cp_code(cp_code)
return jsonify({'success': True, 'orders': orders, 'count': len(orders)}), 200
@warehouse_bp.route('/api/assign-order-to-box', methods=['POST'], endpoint='api_assign_order_to_box')
def api_assign_order_to_box():
"""Assign an order to a box"""
if 'user_id' not in session:
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
data = request.get_json()
order_id = data.get('order_id')
box_id = data.get('box_id')
if not order_id or not box_id:
return jsonify({'success': False, 'error': 'Order ID and box ID are required'}), 400
success, message, status_code = assign_order_to_box(order_id, box_id)
return jsonify({'success': success, 'message': message}), status_code
@warehouse_bp.route('/api/move-order-to-box', methods=['POST'], endpoint='api_move_order_to_box')
def api_move_order_to_box():
"""Move an order to a different box"""
if 'user_id' not in session:
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
data = request.get_json()
order_id = data.get('order_id')
new_box_id = data.get('new_box_id')
if not order_id or not new_box_id:
return jsonify({'success': False, 'error': 'Order ID and destination box ID are required'}), 400
success, message, status_code = move_order_to_box(order_id, new_box_id)
return jsonify({'success': success, 'message': message}), status_code
@warehouse_bp.route('/api/unassign-order', methods=['POST'], endpoint='api_unassign_order')
def api_unassign_order():
"""Remove an order from its box"""
if 'user_id' not in session:
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
data = request.get_json()
order_id = data.get('order_id')
if not order_id:
return jsonify({'success': False, 'error': 'Order ID is required'}), 400
success, message, status_code = unassign_order_from_box(order_id)
return jsonify({'success': success, 'message': message}), status_code
@warehouse_bp.route('/api/boxes-summary', methods=['GET'], endpoint='api_boxes_summary')
def api_boxes_summary():
"""Get summary of all boxes with order counts"""
if 'user_id' not in session:
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
boxes = get_all_boxes_summary()
return jsonify({'success': True, 'boxes': boxes}), 200
# ============================================================================
# API Routes for CP Inventory View
# ============================================================================