Two production bugs from VENDING (order 485224762, 2026-04-22): 1. Oracle: ORA-20000 when a GoMag order contains a kit SKU whose expansion includes CODMAT X plus a second item with SKU=X. Two article-insert call-sites in PACK_IMPORT_COMENZI bypassed merge_or_insert_articol — line 622 (NOM_ARTICOLE fallback) and line 538 (kit discount line). Both now use merge_or_insert_articol for consistent dedup semantics. Regression test added in test_complete_import.py covering the exact kit-plus-direct scenario. 2. SQLite: retry_service._download_and_reimport refreshed orders row but never repopulated order_items. Combined with mark_order_deleted_in_roa (which wipes items), any retry/resync left the UI showing "Niciun articol" despite successful Oracle import. Retry now rebuilds items from the fresh GoMag download on both success and error paths, mirroring sync_service. Includes scripts/backfill_order_items.py — one-shot recovery for orders already in this bad state. Reads settings, re-fetches from GoMag, rewrites order_items without touching Oracle or order status. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
GoMag Import Manager - FastAPI Application
Admin interface si orchestrator pentru importul comenzilor GoMag in Oracle ROA.
Componente
Core
- main.py - Entry point FastAPI, lifespan (Oracle pool + SQLite init), file logging
- config.py - Settings via pydantic-settings (citeste .env)
- database.py - Oracle connection pool + SQLite schema + helpers
Routers (HTTP Endpoints)
| Router | Prefix | Descriere |
|---|---|---|
| health | /health, /api/health | Status Oracle + SQLite |
| dashboard | / | Dashboard HTML cu stat cards |
| mappings | /mappings, /api/mappings | CRUD ARTICOLE_TERTI + CSV |
| articles | /api/articles | Cautare NOM_ARTICOLE |
| validation | /api/validate | Scanare + validare SKU-uri |
| sync | /sync, /api/sync | Import orchestration + scheduler |
Services (Business Logic)
| Service | Rol |
|---|---|
| mapping_service | CRUD pe ARTICOLE_TERTI (Oracle) |
| article_service | Cautare in NOM_ARTICOLE (Oracle) |
| import_service | Port din VFP: partner/address/order creation |
| sync_service | Orchestrare: read JSONs → validate → import → log |
| price_sync_service | Sync preturi GoMag → Oracle politici de pret |
| invoice_service | Verificare facturi ROA + cache SQLite |
| validation_service | Batch-validare SKU-uri (chunks of 500) |
| order_reader | Citire gomag_orders_page*.json din vfp/output/ |
| sqlite_service | CRUD pe SQLite (sync_runs, import_orders, missing_skus) |
| scheduler_service | APScheduler - sync periodic configurabil din UI |
Rulare
pip install -r requirements.txt
# INTOTDEAUNA via start.sh din project root (seteaza Oracle env vars)
cd .. && ./start.sh
Testare
# Din project root:
./test.sh ci # Teste rapide (unit + e2e, ~30s, fara Oracle)
./test.sh full # Teste complete (inclusiv Oracle, ~2-3 min)
./test.sh unit # Doar unit tests
./test.sh e2e # Doar browser tests (Playwright)
./test.sh oracle # Doar Oracle integration
Dual Database
- Oracle - date ERP (ARTICOLE_TERTI, NOM_ARTICOLE, COMENZI)
- SQLite - tracking local (sync_runs, import_orders, missing_skus, scheduler_config)
Logging
Log files in ../logs/sync_comenzi_YYYYMMDD_HHMMSS.log
Format: 2026-03-11 14:30:25 | INFO | app.services.sync_service | mesaj