#!/usr/bin/env python3 """ Debug PACK_IMPORT_COMENZI functions - check correct parameter order """ import oracledb import os import json from datetime import datetime from dotenv import load_dotenv # Load environment load_dotenv('.env') # Oracle configuration user = os.environ['ORACLE_USER'] password = os.environ['ORACLE_PASSWORD'] dsn = os.environ['ORACLE_DSN'] # Initialize Oracle client (thick mode) try: instantclient_path = os.environ.get('INSTANTCLIENTPATH', '/opt/oracle/instantclient_23_9') oracledb.init_oracle_client(lib_dir=instantclient_path) print(f"āœ… Oracle thick mode initialized: {instantclient_path}") except Exception as e: print(f"āš ļø Oracle thick mode failed, using thin mode: {e}") def debug_gaseste_articol(): """Debug gaseste_articol_roa function parameters and results""" print("\nšŸ” Debug PACK_IMPORT_COMENZI.gaseste_articol_roa...") try: with oracledb.connect(user=user, password=password, dsn=dsn) as conn: with conn.cursor() as cur: # Check existing mappings first print("\nšŸ“‹ Existing mappings in ARTICOLE_TERTI:") cur.execute("SELECT sku, codmat, cantitate_roa, procent_pret, activ FROM ARTICOLE_TERTI ORDER BY sku") mappings = cur.fetchall() for mapping in mappings: print(f" {mapping[0]} -> {mapping[1]}: qty={mapping[2]}, pct={mapping[3]}%, active={mapping[4]}") # Test with correct parameter order: p_sku, p_pret_web, p_cantitate_web print("\nā˜• Test CAFE100 with correct parameters:") print(" Parameters: SKU='CAFE100', pret_web=50.0, cantitate_web=2") cur.execute(""" SELECT * FROM TABLE(PACK_IMPORT_COMENZI.gaseste_articol_roa('CAFE100', 50.0, 2)) """) results = cur.fetchall() print(f" Results count: {len(results)}") for i, row in enumerate(results): print(f" Row {i+1}: id_articol={row[0]}, codmat={row[1]}, cant_roa={row[2]}, pret={row[3]}, success={row[4]}, error='{row[5]}'") print("\nšŸŽ Test SET01 with correct parameters:") print(" Parameters: SKU='SET01', pret_web=200.0, cantitate_web=1") cur.execute(""" SELECT * FROM TABLE(PACK_IMPORT_COMENZI.gaseste_articol_roa('SET01', 200.0, 1)) """) results = cur.fetchall() print(f" Results count: {len(results)}") for i, row in enumerate(results): print(f" Row {i+1}: id_articol={row[0]}, codmat={row[1]}, cant_roa={row[2]}, pret={row[3]}, success={row[4]}, error='{row[5]}'") # Test non-existent SKU print("\nā“ Test unknown SKU:") print(" Parameters: SKU='UNKNOWN', pret_web=100.0, cantitate_web=1") cur.execute(""" SELECT * FROM TABLE(PACK_IMPORT_COMENZI.gaseste_articol_roa('UNKNOWN', 100.0, 1)) """) results = cur.fetchall() print(f" Results count: {len(results)}") for i, row in enumerate(results): print(f" Row {i+1}: id_articol={row[0]}, codmat={row[1]}, cant_roa={row[2]}, pret={row[3]}, success={row[4]}, error='{row[5]}'") except Exception as e: print(f"āŒ Debug failed: {e}") def check_nom_articole(): """Check if we have any articles in nom_articole to test with""" print("\nšŸ” Checking nom_articole table...") try: with oracledb.connect(user=user, password=password, dsn=dsn) as conn: with conn.cursor() as cur: # Count total articles cur.execute("SELECT COUNT(*) FROM nom_articole") total_count = cur.fetchone()[0] print(f"Total articles in nom_articole: {total_count}") # Find some sample articles print("\nSample articles (first 10):") cur.execute(""" SELECT id_articol, codmat, denumire FROM nom_articole WHERE ROWNUM <= 10 ORDER BY id_articol """) articles = cur.fetchall() for art in articles: print(f" ID={art[0]}: {art[1]} - {art[2]}") # Look for articles that might match our test SKUs print(f"\nSearching for articles matching test patterns...") test_patterns = ['CAF%', 'FILTR%', '%CAFE%', '%SET%'] for pattern in test_patterns: cur.execute("SELECT codmat, denumire FROM nom_articole WHERE codmat LIKE ? AND ROWNUM <= 3", [pattern]) matches = cur.fetchall() if matches: print(f" Pattern '{pattern}': {matches}") except Exception as e: print(f"āŒ Check nom_articole failed: {e}") def main(): """Run debug functions""" print("šŸ” Debug PACK_IMPORT_COMENZI Functions") print("=" * 50) check_nom_articole() debug_gaseste_articol() if __name__ == "__main__": main()