#!/usr/bin/env python3 """ Test script to verify Excel export functionality """ import os import sys from datetime import datetime # Add src to path sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) from database import DatabaseManager from services import ( ProductService, SupplierService, CustomerService, PurchaseOrderService, ManufacturingOrderService, SalesOrderService, InventoryService ) def test_excel_exports(): """Test all Excel export functionality""" print("Testing Excel Export Functionality...") # Initialize database db_manager = DatabaseManager() # Initialize services product_service = ProductService(db_manager) supplier_service = SupplierService(db_manager) customer_service = CustomerService(db_manager) purchase_service = PurchaseOrderService(db_manager) manufacturing_service = ManufacturingOrderService(db_manager) sales_service = SalesOrderService(db_manager) inventory_service = InventoryService(db_manager) # Create test data print("Creating test data...") # Create a product product = product_service.create_product("Test Product", "Test Description", 100.0) if product: print(f"Created product: {product.name}") # Create a supplier supplier = supplier_service.create_supplier("Test Supplier", "John Doe", "1234567890") if supplier: print(f"Created supplier: {supplier.name}") # Create a customer customer = customer_service.create_customer("Test Customer", "Jane Doe", "0987654321") if customer: print(f"Created customer: {customer.name}") # Create inventory record inventory = inventory_service.create_inventory_record(product.id, 50) if inventory: print(f"Created inventory record for product {product.id}") # Create purchase order po = purchase_service.create_purchase_order(supplier.id) if po: print(f"Created purchase order: {po.id}") # Create manufacturing order mo = manufacturing_service.create_manufacturing_order(product.id, 10) if mo: print(f"Created manufacturing order: {mo.id}") # Create sales order so = sales_service.create_sales_order(customer.id) if so: print(f"Created sales order: {so.id}") # Test exports print("\nTesting Excel exports...") try: # Test purchase order export po_filename = purchase_service.export_to_excel("test_purchase_orders.xlsx") print(f"[OK] Purchase orders exported to: {po_filename}") # Test manufacturing order export mo_filename = manufacturing_service.export_to_excel("test_manufacturing_orders.xlsx") print(f"[OK] Manufacturing orders exported to: {mo_filename}") # Test sales order export so_filename = sales_service.export_to_excel("test_sales_orders.xlsx") print(f"[OK] Sales orders exported to: {so_filename}") # Test inventory export inv_filename = inventory_service.export_to_excel("test_inventory.xlsx") print(f"[OK] Inventory exported to: {inv_filename}") # Test stock movements export sm_filename = inventory_service.export_stock_movements_to_excel("test_stock_movements.xlsx") print(f"[OK] Stock movements exported to: {sm_filename}") print("\n[SUCCESS] All Excel export tests passed!") # Clean up test files test_files = [po_filename, mo_filename, so_filename, inv_filename, sm_filename] for file in test_files: if os.path.exists(file): os.remove(file) print(f"Cleaned up: {file}") except Exception as e: print(f"[ERROR] Error during export: {str(e)}") return False return True if __name__ == "__main__": success = test_excel_exports() if success: print("\n[SUCCESS] All tests completed successfully!") else: print("\n[ERROR] Some tests failed!") sys.exit(1)