Implement print labels module with PDF generation, QZ Tray integration, and theme support
- Migrate print_labels.html and print_lost_labels.html to standalone pages with header and theme toggle - Implement dark/light theme support using data-theme attribute and CSS variables - Add PDF generation endpoints for single and batch label printing - Copy pdf_generator.py from original app with full label formatting (80mm x 105mm) - Fix data response handling to correctly access data.orders from API endpoints - Synchronize table text sizes across both print pages - Remove help buttons from print pages - Database column rename: data_livrara → data_livrare for consistency - Update routes to use correct database column names - Add 7 test orders to database (4 unprinted, 3 printed) - Implement QZ Tray integration with PDF fallback for label printing - All CSS uses theme variables for dark/light mode synchronization
This commit is contained in:
219
documentation/insert_test_data.py
Normal file
219
documentation/insert_test_data.py
Normal file
@@ -0,0 +1,219 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Insert test data into the order_for_labels table for testing print functionality
|
||||
"""
|
||||
import pymysql
|
||||
from datetime import datetime, timedelta
|
||||
import sys
|
||||
|
||||
# Database connection parameters
|
||||
DB_HOST = 'mariadb'
|
||||
DB_PORT = 3306
|
||||
DB_USER = 'quality_user'
|
||||
DB_PASSWORD = 'quality_secure_password_2026'
|
||||
DB_NAME = 'quality_db'
|
||||
|
||||
def insert_test_data():
|
||||
"""Insert test orders into the database"""
|
||||
|
||||
try:
|
||||
# Connect to database
|
||||
conn = pymysql.connect(
|
||||
host=DB_HOST,
|
||||
port=DB_PORT,
|
||||
user=DB_USER,
|
||||
password=DB_PASSWORD,
|
||||
database=DB_NAME,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Check if table exists
|
||||
cursor.execute("SHOW TABLES LIKE 'order_for_labels'")
|
||||
if not cursor.fetchone():
|
||||
print("Error: order_for_labels table does not exist")
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return False
|
||||
|
||||
# Check if printed_labels column exists
|
||||
cursor.execute("SHOW COLUMNS FROM order_for_labels LIKE 'printed_labels'")
|
||||
if not cursor.fetchone():
|
||||
print("Error: printed_labels column does not exist")
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return False
|
||||
|
||||
# Sample test data
|
||||
today = datetime.now()
|
||||
delivery_date = today + timedelta(days=7)
|
||||
|
||||
test_orders = [
|
||||
{
|
||||
'comanda_productie': 'CP00000711',
|
||||
'cod_articol': 'ART001',
|
||||
'descr_com_prod': 'Memory Foam Pillow - Premium Quality',
|
||||
'cantitate': 5,
|
||||
'com_achiz_client': 'PO2026001',
|
||||
'nr_linie_com_client': '001',
|
||||
'customer_name': 'ACME Corporation',
|
||||
'customer_article_number': 'ACME-MFP-001',
|
||||
'open_for_order': 1,
|
||||
'line_number': 1,
|
||||
'data_livrara': delivery_date.date(),
|
||||
'dimensiune': 'Standard (50x70cm)',
|
||||
'printed_labels': 0
|
||||
},
|
||||
{
|
||||
'comanda_productie': 'CP00000712',
|
||||
'cod_articol': 'ART002',
|
||||
'descr_com_prod': 'Gel Infused Mattress Topper',
|
||||
'cantitate': 10,
|
||||
'com_achiz_client': 'PO2026002',
|
||||
'nr_linie_com_client': '001',
|
||||
'customer_name': 'Sleep Solutions Ltd',
|
||||
'customer_article_number': 'SS-GIM-002',
|
||||
'open_for_order': 1,
|
||||
'line_number': 1,
|
||||
'data_livrara': delivery_date.date(),
|
||||
'dimensiune': 'Double (140x200cm)',
|
||||
'printed_labels': 0
|
||||
},
|
||||
{
|
||||
'comanda_productie': 'CP00000713',
|
||||
'cod_articol': 'ART003',
|
||||
'descr_com_prod': 'Cooling Gel Pillow - Twin Pack',
|
||||
'cantitate': 8,
|
||||
'com_achiz_client': 'PO2026003',
|
||||
'nr_linie_com_client': '002',
|
||||
'customer_name': 'Bedding Warehouse',
|
||||
'customer_article_number': 'BW-CGP-003',
|
||||
'open_for_order': 1,
|
||||
'line_number': 2,
|
||||
'data_livrara': delivery_date.date(),
|
||||
'dimensiune': 'King (200x200cm)',
|
||||
'printed_labels': 1
|
||||
},
|
||||
{
|
||||
'comanda_productie': 'CP00000714',
|
||||
'cod_articol': 'ART004',
|
||||
'descr_com_prod': 'Hypoallergenic Pillow Insert',
|
||||
'cantitate': 15,
|
||||
'com_achiz_client': 'PO2026004',
|
||||
'nr_linie_com_client': '001',
|
||||
'customer_name': 'Health Products Inc',
|
||||
'customer_article_number': 'HPI-HYP-004',
|
||||
'open_for_order': 0,
|
||||
'line_number': 1,
|
||||
'data_livrara': delivery_date.date(),
|
||||
'dimensiune': 'Standard (50x70cm)',
|
||||
'printed_labels': 0
|
||||
},
|
||||
{
|
||||
'comanda_productie': 'CP00000715',
|
||||
'cod_articol': 'ART005',
|
||||
'descr_com_prod': 'Memory Foam Mattress 10CM',
|
||||
'cantitate': 3,
|
||||
'com_achiz_client': 'PO2026005',
|
||||
'nr_linie_com_client': '001',
|
||||
'customer_name': 'Premium Comfort Ltd',
|
||||
'customer_article_number': 'PC-MFM-005',
|
||||
'open_for_order': 1,
|
||||
'line_number': 1,
|
||||
'data_livrara': delivery_date.date(),
|
||||
'dimensiune': 'Queen (160x200cm)',
|
||||
'printed_labels': 1
|
||||
},
|
||||
{
|
||||
'comanda_productie': 'CP00000716',
|
||||
'cod_articol': 'ART006',
|
||||
'descr_com_prod': 'Latex Pillow - Eco Friendly',
|
||||
'cantitate': 12,
|
||||
'com_achiz_client': 'PO2026006',
|
||||
'nr_linie_com_client': '003',
|
||||
'customer_name': 'Sustainable Sleep',
|
||||
'customer_article_number': 'SS-LAT-006',
|
||||
'open_for_order': 1,
|
||||
'line_number': 3,
|
||||
'data_livrara': delivery_date.date(),
|
||||
'dimensiune': 'Standard (50x70cm)',
|
||||
'printed_labels': 0
|
||||
},
|
||||
{
|
||||
'comanda_productie': 'CP00000717',
|
||||
'cod_articol': 'ART007',
|
||||
'descr_com_prod': 'Body Pillow with Cover',
|
||||
'cantitate': 6,
|
||||
'com_achiz_client': 'PO2026007',
|
||||
'nr_linie_com_client': '001',
|
||||
'customer_name': 'Comfort Essentials',
|
||||
'customer_article_number': 'CE-BP-007',
|
||||
'open_for_order': 1,
|
||||
'line_number': 1,
|
||||
'data_livrara': delivery_date.date(),
|
||||
'dimensiune': 'Long (40x150cm)',
|
||||
'printed_labels': 1
|
||||
}
|
||||
]
|
||||
|
||||
# Insert test data
|
||||
insert_query = """
|
||||
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, data_livrara, dimensiune, printed_labels,
|
||||
created_at, updated_at)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW(), NOW())
|
||||
"""
|
||||
|
||||
inserted = 0
|
||||
for order in test_orders:
|
||||
try:
|
||||
cursor.execute(insert_query, (
|
||||
order['comanda_productie'],
|
||||
order['cod_articol'],
|
||||
order['descr_com_prod'],
|
||||
order['cantitate'],
|
||||
order['com_achiz_client'],
|
||||
order['nr_linie_com_client'],
|
||||
order['customer_name'],
|
||||
order['customer_article_number'],
|
||||
order['open_for_order'],
|
||||
order['line_number'],
|
||||
order['data_livrara'],
|
||||
order['dimensiune'],
|
||||
order['printed_labels']
|
||||
))
|
||||
inserted += 1
|
||||
print(f"✓ Inserted: {order['comanda_productie']} - {order['descr_com_prod'][:40]}")
|
||||
except Exception as e:
|
||||
print(f"✗ Failed to insert {order['comanda_productie']}: {e}")
|
||||
|
||||
# Commit the transaction
|
||||
conn.commit()
|
||||
|
||||
# Show summary
|
||||
cursor.execute("SELECT COUNT(*) FROM order_for_labels")
|
||||
total_orders = cursor.fetchone()[0]
|
||||
|
||||
print(f"\n{'='*60}")
|
||||
print(f"Test data insertion completed!")
|
||||
print(f"Inserted: {inserted} new orders")
|
||||
print(f"Total orders in database: {total_orders}")
|
||||
print(f"{'='*60}")
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
except pymysql.Error as e:
|
||||
print(f"Database error: {e}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"Unexpected error: {e}")
|
||||
return False
|
||||
|
||||
if __name__ == '__main__':
|
||||
success = insert_test_data()
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in New Issue
Block a user