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:
Quality App Developer
2026-02-15 12:05:20 +02:00
parent 134fc73f9c
commit d5b043c762
83 changed files with 415 additions and 2 deletions

View File

@@ -0,0 +1,260 @@
#!/usr/bin/env python3
"""
Add Example/Test Data for Labels Module
Creates sample orders in order_for_labels table for testing printing functionality via QZ Tray
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from app.database import get_db
import logging
from datetime import datetime, timedelta
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def add_sample_labels_data():
"""Add sample order data for testing labels/printing functionality"""
try:
conn = get_db()
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 = [
{
'comanda_productie': 'TEST-ORD-001',
'cod_articol': 'ART001',
'descr_com_prod': 'Electronic Component Type A - High Performance',
'cantitate': 150,
'com_achiz_client': 'CLIENT-PO-2024-001',
'nr_linie_com_client': '01',
'customer_name': 'TechCorp Industries',
'customer_article_number': 'TC-COMP-A001',
'open_for_order': 1,
'line_number': 1,
'printed_labels': 0, # Not printed - will show in unprinted list
'data_livrara': '2024-03-15', # Fixed field name to match DB schema
'dimensiune': 'Standard-Large'
},
{
'comanda_productie': 'TEST-ORD-002',
'cod_articol': 'ART002',
'descr_com_prod': 'Mechanical Part B - Precision Machined',
'cantitate': 75,
'com_achiz_client': 'CLIENT-PO-2024-002',
'nr_linie_com_client': '02',
'customer_name': 'MechParts Ltd',
'customer_article_number': 'MP-PART-B002',
'open_for_order': 1,
'line_number': 2,
'printed_labels': 0, # Not printed
'data_livrara': '2024-03-18',
'dimensiune': 'Medium'
},
{
'comanda_productie': 'TEST-ORD-003',
'cod_articol': 'ART003',
'descr_com_prod': 'Plastic Housing C - UV Resistant',
'cantitate': 200,
'com_achiz_client': 'CLIENT-PO-2024-003',
'nr_linie_com_client': '03',
'customer_name': 'PlasticWorks Inc',
'customer_article_number': 'PW-HOUSE-C003',
'open_for_order': 1,
'line_number': 3,
'printed_labels': 1, # Already printed - will show in printed list
'data_livrara': '2024-03-20',
'dimensiune': 'Large'
},
{
'comanda_productie': 'TEST-ORD-004',
'cod_articol': 'ART004',
'descr_com_prod': 'Metal Bracket D - Galvanized Steel',
'cantitate': 300,
'com_achiz_client': 'CLIENT-PO-2024-004',
'nr_linie_com_client': '04',
'customer_name': 'MetalCraft Solutions',
'customer_article_number': 'MC-BRACK-D004',
'open_for_order': 1,
'line_number': 4,
'printed_labels': 0, # Not printed
'data_livrara': '2024-03-22',
'dimensiune': 'Small'
},
{
'comanda_productie': 'TEST-ORD-005',
'cod_articol': 'ART005',
'descr_com_prod': 'Circuit Board E - Multi-layer PCB',
'cantitate': 50,
'com_achiz_client': 'CLIENT-PO-2024-005',
'nr_linie_com_client': '05',
'customer_name': 'CircuitTech Systems',
'customer_article_number': 'CT-PCB-E005',
'open_for_order': 1,
'line_number': 5,
'printed_labels': 0, # Not printed
'data_livrara': '2024-03-25',
'dimensiune': 'Standard'
},
{
'comanda_productie': 'TEST-ORD-006',
'cod_articol': 'ART006',
'descr_com_prod': 'Rubber Gasket F - High Temperature',
'cantitate': 500,
'com_achiz_client': 'CLIENT-PO-2024-006',
'nr_linie_com_client': '06',
'customer_name': 'RubberPro Manufacturing',
'customer_article_number': 'RP-GASKET-F006',
'open_for_order': 1,
'line_number': 6,
'printed_labels': 1, # Already printed
'data_livrara': '2024-03-28',
'dimensiune': 'Extra-Small'
},
{
'comanda_productie': 'TEST-ORD-007',
'cod_articol': 'ART007',
'descr_com_prod': 'Glass Panel G - Tempered Safety Glass',
'cantitate': 25,
'com_achiz_client': 'CLIENT-PO-2024-007',
'nr_linie_com_client': '07',
'customer_name': 'GlassTech Innovations',
'customer_article_number': 'GT-PANEL-G007',
'open_for_order': 1,
'line_number': 7,
'printed_labels': 0, # Not printed - urgent order
'data_livrara': '2024-03-12', # Past due date for testing
'dimensiune': 'Extra-Large'
},
{
'comanda_productie': 'TEST-ORD-008',
'cod_articol': 'ART008',
'descr_com_prod': 'Fabric Cover H - Water-Resistant Canvas',
'cantitate': 120,
'com_achiz_client': 'CLIENT-PO-2024-008',
'nr_linie_com_client': '08',
'customer_name': 'FabricWorks Design',
'customer_article_number': 'FW-COVER-H008',
'open_for_order': 0, # Not open for order - for testing
'line_number': 8,
'printed_labels': 0,
'data_livrara': '2024-04-01',
'dimensiune': 'Custom'
}
]
# Insert test data
logger.info(f"Inserting {len(test_orders)} test orders...")
for order in test_orders:
cursor.execute("""
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 (
%(comanda_productie)s, %(cod_articol)s, %(descr_com_prod)s, %(cantitate)s,
%(com_achiz_client)s, %(nr_linie_com_client)s, %(customer_name)s,
%(customer_article_number)s, %(open_for_order)s, %(line_number)s,
%(printed_labels)s, %(data_livrara)s, %(dimensiune)s
)
""", order)
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['printed_labels'] == 0)}")
logger.info(f" - Printed orders: {sum(1 for o in test_orders if o['printed_labels'] == 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 = get_db()
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"
logger.info(f" - {order[0]}: {order[1][:50]}... (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. Start the application: docker compose up -d")
logger.info("2. Navigate to: http://localhost:8080/labels/print-module")
logger.info("3. Test QZ Tray printing functionality")
else:
logger.error("❌ Failed to add test data")
sys.exit(1)