Add Set Boxes Locations page with status management and remove company branding from labels
- Renamed Store Articles card to Set Boxes Locations on warehouse main page - Created new mobile-optimized page with two tabs for box location management: - Tab 1: Assign box to location (scan box, change status to closed, assign location) - Tab 2: Move box from location (scan location, list boxes, move to new location) - Added box status management (open/closed) with status change button - Enforced rule: only closed boxes can be assigned to locations - Moved API logic to warehouse.py module: - search_box_by_number() - assign_box_to_location() - search_location_with_boxes() - move_box_to_new_location() - change_box_status() - Added API routes in routes.py as thin wrappers - Aligned page theme colors with application Bootstrap theme - Added dark mode support for the new page - Added Warehouse Main button to page header - Removed 'INNOFA ROMANIA SRL' branding from: - Print module label preview and PDF generation - Print lost labels page - pdf_generator.py PDF creation function
This commit is contained in:
@@ -710,3 +710,270 @@ def view_warehouse_inventory_handler():
|
||||
return f"<h1>Error loading warehouse inventory</h1><pre>{error_trace}</pre>", 500
|
||||
|
||||
|
||||
# Box Location Management Functions
|
||||
|
||||
def search_box_by_number(box_number):
|
||||
"""
|
||||
Search for a box by box number and return its details including location
|
||||
|
||||
Args:
|
||||
box_number (str): The box number to search for
|
||||
|
||||
Returns:
|
||||
tuple: (success: bool, data: dict, status_code: int)
|
||||
"""
|
||||
try:
|
||||
if not box_number:
|
||||
return False, {'message': 'Box number is required'}, 400
|
||||
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Search for the box and get its location info
|
||||
cursor.execute("""
|
||||
SELECT
|
||||
b.id,
|
||||
b.box_number,
|
||||
b.status,
|
||||
b.location_id,
|
||||
w.location_code
|
||||
FROM boxes_crates b
|
||||
LEFT JOIN warehouse_locations w ON b.location_id = w.id
|
||||
WHERE b.box_number = %s
|
||||
""", (box_number,))
|
||||
|
||||
result = cursor.fetchone()
|
||||
conn.close()
|
||||
|
||||
if result:
|
||||
return True, {
|
||||
'box': {
|
||||
'id': result[0],
|
||||
'box_number': result[1],
|
||||
'status': result[2],
|
||||
'location_id': result[3],
|
||||
'location_code': result[4]
|
||||
}
|
||||
}, 200
|
||||
else:
|
||||
return False, {'message': f'Box "{box_number}" not found in the system'}, 404
|
||||
|
||||
except Exception as e:
|
||||
return False, {'message': f'Error searching for box: {str(e)}'}, 500
|
||||
|
||||
|
||||
def assign_box_to_location(box_id, location_code):
|
||||
"""
|
||||
Assign a box to a warehouse location
|
||||
|
||||
Args:
|
||||
box_id (int): The ID of the box to assign
|
||||
location_code (str): The location code to assign the box to
|
||||
|
||||
Returns:
|
||||
tuple: (success: bool, data: dict, status_code: int)
|
||||
"""
|
||||
try:
|
||||
if not box_id or not location_code:
|
||||
return False, {'message': 'Box ID and location code are required'}, 400
|
||||
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Check if location exists
|
||||
cursor.execute("SELECT id FROM warehouse_locations WHERE location_code = %s", (location_code,))
|
||||
location_result = cursor.fetchone()
|
||||
|
||||
if not location_result:
|
||||
conn.close()
|
||||
return False, {'message': f'Location "{location_code}" not found in the system'}, 404
|
||||
|
||||
location_id = location_result[0]
|
||||
|
||||
# Update box location
|
||||
cursor.execute("""
|
||||
UPDATE boxes_crates
|
||||
SET location_id = %s, updated_at = NOW()
|
||||
WHERE id = %s
|
||||
""", (location_id, box_id))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
return True, {'message': f'Box successfully assigned to location "{location_code}"'}, 200
|
||||
|
||||
except Exception as e:
|
||||
return False, {'message': f'Error assigning box to location: {str(e)}'}, 500
|
||||
|
||||
|
||||
def search_location_with_boxes(location_code):
|
||||
"""
|
||||
Search for a location and get all boxes assigned to it
|
||||
|
||||
Args:
|
||||
location_code (str): The location code to search for
|
||||
|
||||
Returns:
|
||||
tuple: (success: bool, data: dict, status_code: int)
|
||||
"""
|
||||
try:
|
||||
if not location_code:
|
||||
return False, {'message': 'Location code is required'}, 400
|
||||
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Search for the location
|
||||
cursor.execute("""
|
||||
SELECT id, location_code, size, description
|
||||
FROM warehouse_locations
|
||||
WHERE location_code = %s
|
||||
""", (location_code,))
|
||||
|
||||
location_result = cursor.fetchone()
|
||||
|
||||
if not location_result:
|
||||
conn.close()
|
||||
return False, {'message': f'Location "{location_code}" not found in the system'}, 404
|
||||
|
||||
location_id = location_result[0]
|
||||
|
||||
# Get all boxes assigned to this location
|
||||
cursor.execute("""
|
||||
SELECT
|
||||
b.id,
|
||||
b.box_number,
|
||||
b.status,
|
||||
b.created_at
|
||||
FROM boxes_crates b
|
||||
WHERE b.location_id = %s
|
||||
ORDER BY b.box_number
|
||||
""", (location_id,))
|
||||
|
||||
boxes_results = cursor.fetchall()
|
||||
conn.close()
|
||||
|
||||
boxes = []
|
||||
for box in boxes_results:
|
||||
boxes.append({
|
||||
'id': box[0],
|
||||
'box_number': box[1],
|
||||
'status': box[2],
|
||||
'created_at': box[3].strftime('%Y-%m-%d %H:%M:%S') if box[3] else None
|
||||
})
|
||||
|
||||
return True, {
|
||||
'location': {
|
||||
'id': location_result[0],
|
||||
'location_code': location_result[1],
|
||||
'size': location_result[2],
|
||||
'description': location_result[3]
|
||||
},
|
||||
'boxes': boxes
|
||||
}, 200
|
||||
|
||||
except Exception as e:
|
||||
return False, {'message': f'Error searching for location: {str(e)}'}, 500
|
||||
|
||||
|
||||
def move_box_to_new_location(box_id, new_location_code):
|
||||
"""
|
||||
Move a box from its current location to a new location
|
||||
|
||||
Args:
|
||||
box_id (int): The ID of the box to move
|
||||
new_location_code (str): The new location code
|
||||
|
||||
Returns:
|
||||
tuple: (success: bool, data: dict, status_code: int)
|
||||
"""
|
||||
try:
|
||||
if not box_id or not new_location_code:
|
||||
return False, {'message': 'Box ID and new location code are required'}, 400
|
||||
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Check if new location exists
|
||||
cursor.execute("SELECT id FROM warehouse_locations WHERE location_code = %s", (new_location_code,))
|
||||
location_result = cursor.fetchone()
|
||||
|
||||
if not location_result:
|
||||
conn.close()
|
||||
return False, {'message': f'Location "{new_location_code}" not found in the system'}, 404
|
||||
|
||||
new_location_id = location_result[0]
|
||||
|
||||
# Get box number for response message
|
||||
cursor.execute("SELECT box_number FROM boxes_crates WHERE id = %s", (box_id,))
|
||||
box_result = cursor.fetchone()
|
||||
|
||||
if not box_result:
|
||||
conn.close()
|
||||
return False, {'message': 'Box not found'}, 404
|
||||
|
||||
box_number = box_result[0]
|
||||
|
||||
# Update box location
|
||||
cursor.execute("""
|
||||
UPDATE boxes_crates
|
||||
SET location_id = %s, updated_at = NOW()
|
||||
WHERE id = %s
|
||||
""", (new_location_id, box_id))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
return True, {'message': f'Box "{box_number}" successfully moved to location "{new_location_code}"'}, 200
|
||||
|
||||
except Exception as e:
|
||||
return False, {'message': f'Error moving box to new location: {str(e)}'}, 500
|
||||
|
||||
|
||||
def change_box_status(box_id, new_status):
|
||||
"""
|
||||
Change the status of a box (open/closed)
|
||||
|
||||
Args:
|
||||
box_id (int): The ID of the box
|
||||
new_status (str): The new status ('open' or 'closed')
|
||||
|
||||
Returns:
|
||||
tuple: (success: bool, data: dict, status_code: int)
|
||||
"""
|
||||
try:
|
||||
if not box_id:
|
||||
return False, {'message': 'Box ID is required'}, 400
|
||||
|
||||
if new_status not in ['open', 'closed']:
|
||||
return False, {'message': 'Invalid status. Must be "open" or "closed"'}, 400
|
||||
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Get box number for response message
|
||||
cursor.execute("SELECT box_number FROM boxes_crates WHERE id = %s", (box_id,))
|
||||
box_result = cursor.fetchone()
|
||||
|
||||
if not box_result:
|
||||
conn.close()
|
||||
return False, {'message': 'Box not found'}, 404
|
||||
|
||||
box_number = box_result[0]
|
||||
|
||||
# Update box status
|
||||
cursor.execute("""
|
||||
UPDATE boxes_crates
|
||||
SET status = %s, updated_at = NOW()
|
||||
WHERE id = %s
|
||||
""", (new_status, box_id))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
return True, {'message': f'Box "{box_number}" status changed to "{new_status}"'}, 200
|
||||
|
||||
except Exception as e:
|
||||
return False, {'message': f'Error changing box status: {str(e)}'}, 500
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user