Fix Docker build and add labels test data
- Fix Docker build issues: * Add missing system dependencies (build-essential, python3-dev, libpq-dev) * Fix requirements.txt formatting (separate Flask-Session and openpyxl) * Update openpyxl version to 3.1.5 (3.10.0 was invalid) - Set proper folder permissions for Docker write access (app/ and data/) - Add comprehensive test data for labels module: * 8 sample orders (TEST-ORD-001 through TEST-ORD-008) * Mix of printed/unprinted orders for testing * Various product types, customers, and delivery dates * Ready for QZ Tray printing functionality testing - Include test data generation scripts for future use - Application now fully containerized and ready for labels/printing testing
This commit is contained in:
149
documentation/add_labels_test_data_direct.py
Normal file
149
documentation/add_labels_test_data_direct.py
Normal file
@@ -0,0 +1,149 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Add Example/Test Data for Labels Module - Direct Database Version
|
||||
Creates sample orders in order_for_labels table for testing printing functionality via QZ Tray
|
||||
"""
|
||||
|
||||
import pymysql
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Database connection parameters
|
||||
DB_CONFIG = {
|
||||
'host': 'localhost',
|
||||
'port': 3306,
|
||||
'user': 'quality_user',
|
||||
'password': 'qualitypass',
|
||||
'database': 'quality_db',
|
||||
'charset': 'utf8mb4'
|
||||
}
|
||||
|
||||
def add_sample_labels_data():
|
||||
"""Add sample order data for testing labels/printing functionality"""
|
||||
try:
|
||||
# Connect to database
|
||||
conn = pymysql.connect(**DB_CONFIG)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Check if table exists
|
||||
cursor.execute("SHOW TABLES LIKE 'order_for_labels'")
|
||||
if not cursor.fetchone():
|
||||
logger.error("order_for_labels table does not exist. Please run initialize_db.py first.")
|
||||
return False
|
||||
|
||||
# Clear existing test data (optional - comment out if you want to keep existing data)
|
||||
logger.info("Clearing existing test data...")
|
||||
cursor.execute("DELETE FROM order_for_labels WHERE comanda_productie LIKE 'TEST%'")
|
||||
|
||||
# Sample test data for different scenarios
|
||||
test_orders = [
|
||||
('TEST-ORD-001', 'ART001', 'Electronic Component Type A - High Performance', 150, 'CLIENT-PO-2024-001', '01', 'TechCorp Industries', 'TC-COMP-A001', 1, 1, 0, '2024-03-15', 'Standard-Large'),
|
||||
('TEST-ORD-002', 'ART002', 'Mechanical Part B - Precision Machined', 75, 'CLIENT-PO-2024-002', '02', 'MechParts Ltd', 'MP-PART-B002', 1, 2, 0, '2024-03-18', 'Medium'),
|
||||
('TEST-ORD-003', 'ART003', 'Plastic Housing C - UV Resistant', 200, 'CLIENT-PO-2024-003', '03', 'PlasticWorks Inc', 'PW-HOUSE-C003', 1, 3, 1, '2024-03-20', 'Large'),
|
||||
('TEST-ORD-004', 'ART004', 'Metal Bracket D - Galvanized Steel', 300, 'CLIENT-PO-2024-004', '04', 'MetalCraft Solutions', 'MC-BRACK-D004', 1, 4, 0, '2024-03-22', 'Small'),
|
||||
('TEST-ORD-005', 'ART005', 'Circuit Board E - Multi-layer PCB', 50, 'CLIENT-PO-2024-005', '05', 'CircuitTech Systems', 'CT-PCB-E005', 1, 5, 0, '2024-03-25', 'Standard'),
|
||||
('TEST-ORD-006', 'ART006', 'Rubber Gasket F - High Temperature', 500, 'CLIENT-PO-2024-006', '06', 'RubberPro Manufacturing', 'RP-GASKET-F006', 1, 6, 1, '2024-03-28', 'Extra-Small'),
|
||||
('TEST-ORD-007', 'ART007', 'Glass Panel G - Tempered Safety Glass', 25, 'CLIENT-PO-2024-007', '07', 'GlassTech Innovations', 'GT-PANEL-G007', 1, 7, 0, '2024-03-12', 'Extra-Large'),
|
||||
('TEST-ORD-008', 'ART008', 'Fabric Cover H - Water-Resistant Canvas', 120, 'CLIENT-PO-2024-008', '08', 'FabricWorks Design', 'FW-COVER-H008', 0, 8, 0, '2024-04-01', 'Custom'),
|
||||
]
|
||||
|
||||
# Insert test data
|
||||
logger.info(f"Inserting {len(test_orders)} test orders...")
|
||||
|
||||
cursor.executemany("""
|
||||
INSERT INTO order_for_labels (
|
||||
comanda_productie, cod_articol, descr_com_prod, cantitate,
|
||||
com_achiz_client, nr_linie_com_client, customer_name,
|
||||
customer_article_number, open_for_order, line_number,
|
||||
printed_labels, data_livrara, dimensiune
|
||||
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
""", test_orders)
|
||||
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
logger.info("✅ Successfully added test data for labels module!")
|
||||
logger.info("Test data summary:")
|
||||
logger.info(f" - Total orders: {len(test_orders)}")
|
||||
logger.info(f" - Unprinted orders: {sum(1 for o in test_orders if o[10] == 0)}") # printed_labels is index 10
|
||||
logger.info(f" - Printed orders: {sum(1 for o in test_orders if o[10] == 1)}")
|
||||
logger.info(" - Test order codes: TEST-ORD-001 through TEST-ORD-008")
|
||||
logger.info("\nYou can now test:")
|
||||
logger.info(" 1. Navigate to /labels/print-module")
|
||||
logger.info(" 2. View unprinted orders (should show 6 orders)")
|
||||
logger.info(" 3. Generate PDF labels and test QZ Tray printing")
|
||||
logger.info(" 4. Mark orders as printed and verify status updates")
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error adding test data: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def verify_test_data():
|
||||
"""Verify that test data was added correctly"""
|
||||
try:
|
||||
conn = pymysql.connect(**DB_CONFIG)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Count total test orders
|
||||
cursor.execute("SELECT COUNT(*) FROM order_for_labels WHERE comanda_productie LIKE 'TEST%'")
|
||||
total_count = cursor.fetchone()[0]
|
||||
|
||||
# Count unprinted test orders
|
||||
cursor.execute("SELECT COUNT(*) FROM order_for_labels WHERE comanda_productie LIKE 'TEST%' AND printed_labels = 0")
|
||||
unprinted_count = cursor.fetchone()[0]
|
||||
|
||||
# Count printed test orders
|
||||
cursor.execute("SELECT COUNT(*) FROM order_for_labels WHERE comanda_productie LIKE 'TEST%' AND printed_labels = 1")
|
||||
printed_count = cursor.fetchone()[0]
|
||||
|
||||
logger.info(f"\n📋 Test Data Verification:")
|
||||
logger.info(f" - Total test orders: {total_count}")
|
||||
logger.info(f" - Unprinted orders: {unprinted_count}")
|
||||
logger.info(f" - Printed orders: {printed_count}")
|
||||
|
||||
# List some sample orders
|
||||
cursor.execute("""
|
||||
SELECT comanda_productie, descr_com_prod, cantitate, printed_labels, data_livrara
|
||||
FROM order_for_labels
|
||||
WHERE comanda_productie LIKE 'TEST%'
|
||||
ORDER BY comanda_productie
|
||||
LIMIT 5
|
||||
""")
|
||||
|
||||
orders = cursor.fetchall()
|
||||
if orders:
|
||||
logger.info(f"\n🏷️ Sample Test Orders:")
|
||||
for order in orders:
|
||||
status = "✅ Printed" if order[3] else "⏳ Unprinted"
|
||||
desc = order[1][:50] + "..." if len(order[1]) > 50 else order[1]
|
||||
logger.info(f" - {order[0]}: {desc} (Qty: {order[2]}, {status})")
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error verifying test data: {e}")
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logger.info("🏷️ Adding Labels Module Test Data...")
|
||||
|
||||
if add_sample_labels_data():
|
||||
verify_test_data()
|
||||
logger.info("\n🎉 Test data successfully added!")
|
||||
logger.info("\nNext steps:")
|
||||
logger.info("1. Navigate to: http://localhost:8781/labels/print-module")
|
||||
logger.info("2. Test QZ Tray printing functionality")
|
||||
logger.info("3. Use test orders TEST-ORD-001 through TEST-ORD-008")
|
||||
else:
|
||||
logger.error("❌ Failed to add test data")
|
||||
Reference in New Issue
Block a user