Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Test script for PO and GRN number generation. | |
| Run this to verify the auto-generation functionality works correctly. | |
| """ | |
| import asyncio | |
| import sys | |
| import os | |
| # Add the app directory to Python path | |
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'app')) | |
| from app.purchases.utils import ( | |
| generate_po_no, generate_grn_no, | |
| get_next_po_number, get_next_grn_number, | |
| initialize_sequences | |
| ) | |
| from app.sql import async_session | |
| async def test_number_generation(): | |
| """Test PO and GRN number generation""" | |
| print("🧪 Testing PO/GRN Number Generation") | |
| print("=" * 50) | |
| # Test static generation functions | |
| print("\n📋 Static Number Generation:") | |
| po_no_1 = generate_po_no(1) | |
| po_no_100 = generate_po_no(100) | |
| grn_no_1 = generate_grn_no(1) | |
| grn_no_50 = generate_grn_no(50) | |
| print(f"PO #1: {po_no_1}") | |
| print(f"PO #100: {po_no_100}") | |
| print(f"GRN #1: {grn_no_1}") | |
| print(f"GRN #50: {grn_no_50}") | |
| # Test database sequence generation | |
| print("\n🔢 Database Sequence Generation:") | |
| try: | |
| async with async_session() as session: | |
| # Initialize sequences | |
| await initialize_sequences(session) | |
| print("✅ Sequences initialized") | |
| # Generate PO numbers | |
| po1 = await get_next_po_number(session) | |
| po2 = await get_next_po_number(session) | |
| po3 = await get_next_po_number(session) | |
| print(f"Next PO #1: {po1}") | |
| print(f"Next PO #2: {po2}") | |
| print(f"Next PO #3: {po3}") | |
| # Generate GRN numbers | |
| grn1 = await get_next_grn_number(session) | |
| grn2 = await get_next_grn_number(session) | |
| grn3 = await get_next_grn_number(session) | |
| print(f"Next GRN #1: {grn1}") | |
| print(f"Next GRN #2: {grn2}") | |
| print(f"Next GRN #3: {grn3}") | |
| # Test custom prefixes | |
| custom_po = await get_next_po_number(session, "URGENT") | |
| custom_grn = await get_next_grn_number(session, "BATCH") | |
| print(f"Custom PO: {custom_po}") | |
| print(f"Custom GRN: {custom_grn}") | |
| except Exception as e: | |
| print(f"❌ Database test failed: {e}") | |
| return False | |
| print("\n✅ All tests passed!") | |
| return True | |
| if __name__ == "__main__": | |
| success = asyncio.run(test_number_generation()) | |
| sys.exit(0 if success else 1) |