- PACK_IMPORT_COMENZI: reads optional "id_pol" per article from JSON, uses it via NVL(v_id_pol_articol, p_id_pol) — enables separate price policy for transport/discount articles vs regular order articles - README.md: add Windows deploy section (deploy.ps1, update.ps1, .env example) - CLAUDE.md: add reference to Windows deploy docs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
280 lines
9.7 KiB
Markdown
280 lines
9.7 KiB
Markdown
# GoMag Vending - Import Comenzi Web → ROA Oracle
|
|
|
|
System automat de import comenzi din platforma GoMag in sistemul ERP ROA Oracle.
|
|
|
|
## Arhitectura
|
|
|
|
```
|
|
[GoMag API] → [Python Sync Service] → [Oracle PL/SQL] → [FastAPI Admin]
|
|
↓ ↓ ↑ ↑
|
|
JSON Orders Download/Parse/Import Store/Update Dashboard + Config
|
|
```
|
|
|
|
### Stack Tehnologic
|
|
- **API + Admin:** FastAPI + Jinja2 + Bootstrap 5.3
|
|
- **GoMag Integration:** Python (`gomag_client.py` — download comenzi cu paginare)
|
|
- **Sync Orchestrator:** Python (`sync_service.py` — download → parse → validate → import)
|
|
- **Database:** Oracle PL/SQL packages (IMPORT_PARTENERI, IMPORT_COMENZI) + SQLite (tracking)
|
|
|
|
---
|
|
|
|
## Quick Start
|
|
|
|
### Prerequisite
|
|
- Python 3.10+
|
|
- Oracle Instant Client 21.x (optional — suporta si thin mode pentru Oracle 12.1+)
|
|
|
|
### Instalare
|
|
|
|
```bash
|
|
pip install -r api/requirements.txt
|
|
cp api/.env.example api/.env
|
|
# Editeaza api/.env cu datele de conectare Oracle
|
|
```
|
|
|
|
### Pornire server
|
|
|
|
**Important:** serverul trebuie pornit **din project root**, nu din `api/`:
|
|
|
|
```bash
|
|
python -m uvicorn api.app.main:app --host 0.0.0.0 --port 5003
|
|
```
|
|
|
|
Sau folosind scriptul inclus:
|
|
```bash
|
|
./start.sh
|
|
```
|
|
|
|
Deschide `http://localhost:5003` in browser.
|
|
|
|
### Testare
|
|
|
|
**Test A - Basic (fara Oracle):**
|
|
```bash
|
|
python api/test_app_basic.py
|
|
```
|
|
|
|
**Test C - Integrare Oracle:**
|
|
```bash
|
|
python api/test_integration.py
|
|
```
|
|
|
|
---
|
|
|
|
## Configurare (.env)
|
|
|
|
Copiaza `.env.example` si completeaza:
|
|
|
|
```bash
|
|
cp api/.env.example api/.env
|
|
```
|
|
|
|
| Variabila | Descriere | Exemplu |
|
|
|-----------|-----------|---------|
|
|
| `ORACLE_USER` | User Oracle | `MARIUSM_AUTO` |
|
|
| `ORACLE_PASSWORD` | Parola Oracle | `secret` |
|
|
| `ORACLE_DSN` | TNS alias | `ROA_CENTRAL` |
|
|
| `TNS_ADMIN` | Cale absoluta la tnsnames.ora | `/mnt/e/.../gomag/api` |
|
|
| `INSTANTCLIENTPATH` | Cale Instant Client (thick mode) | `/opt/oracle/instantclient_21_15` |
|
|
| `FORCE_THIN_MODE` | Thin mode fara Instant Client | `true` |
|
|
| `SQLITE_DB_PATH` | Path SQLite (relativ la project root) | `api/data/import.db` |
|
|
| `JSON_OUTPUT_DIR` | Folder JSON-uri descarcate | `api/data/orders` |
|
|
| `APP_PORT` | Port HTTP | `5003` |
|
|
| `ID_POL` | ID Politica ROA | `39` |
|
|
| `ID_GESTIUNE` | ID Gestiune ROA | `0` |
|
|
| `ID_SECTIE` | ID Sectie ROA | `6` |
|
|
|
|
**Nota Oracle mode:**
|
|
- **Thick mode** (Oracle 10g/11g): seteaza `INSTANTCLIENTPATH`
|
|
- **Thin mode** (Oracle 12.1+): seteaza `FORCE_THIN_MODE=true`, sterge `INSTANTCLIENTPATH`
|
|
|
|
---
|
|
|
|
## Structura Proiect
|
|
|
|
```
|
|
gomag-vending/
|
|
├── api/ # FastAPI Admin + Dashboard
|
|
│ ├── app/
|
|
│ │ ├── main.py # Entry point, lifespan, logging
|
|
│ │ ├── config.py # Settings (pydantic-settings + .env)
|
|
│ │ ├── database.py # Oracle pool + SQLite schema + migrari
|
|
│ │ ├── routers/ # Endpoint-uri HTTP
|
|
│ │ │ ├── health.py # GET /health
|
|
│ │ │ ├── dashboard.py # GET / (HTML)
|
|
│ │ │ ├── mappings.py # /mappings, /api/mappings
|
|
│ │ │ ├── articles.py # /api/articles/search
|
|
│ │ │ ├── validation.py # /api/validate/*
|
|
│ │ │ └── sync.py # /api/sync/* + /api/dashboard/orders
|
|
│ │ ├── services/
|
|
│ │ │ ├── gomag_client.py # Download comenzi GoMag API
|
|
│ │ │ ├── sync_service.py # Orchestrare: download→validate→import
|
|
│ │ │ ├── import_service.py # Import comanda in Oracle ROA
|
|
│ │ │ ├── mapping_service.py # CRUD ARTICOLE_TERTI + pct_total
|
|
│ │ │ ├── sqlite_service.py # Tracking runs/orders/missing SKUs
|
|
│ │ │ ├── order_reader.py # Citire gomag_orders_page*.json
|
|
│ │ │ ├── validation_service.py
|
|
│ │ │ ├── article_service.py
|
|
│ │ │ ├── invoice_service.py # Verificare facturi ROA
|
|
│ │ │ └── scheduler_service.py # APScheduler timer
|
|
│ │ ├── templates/ # Jinja2 HTML
|
|
│ │ └── static/ # CSS + JS
|
|
│ ├── database-scripts/ # Oracle SQL (ARTICOLE_TERTI, packages)
|
|
│ ├── data/ # SQLite DB (import.db) + JSON orders
|
|
│ ├── .env # Configurare locala (nu in git)
|
|
│ ├── .env.example # Template configurare
|
|
│ ├── test_app_basic.py # Test A - fara Oracle
|
|
│ ├── test_integration.py # Test C - cu Oracle
|
|
│ └── requirements.txt
|
|
├── logs/ # Log-uri aplicatie (sync_comenzi_*.log)
|
|
├── docs/ # Documentatie (PRD, stories)
|
|
├── screenshots/ # Before/preview/after pentru UI changes
|
|
├── start.sh # Script pornire (Linux/WSL)
|
|
└── CLAUDE.md # Instructiuni pentru AI assistants
|
|
```
|
|
|
|
---
|
|
|
|
## Dashboard Features
|
|
|
|
### Sync Panel
|
|
- Start sync manual sau scheduler automat (5/10/30 min)
|
|
- Progress live: `"Import 45/80: #CMD-1234 Ion Popescu"`
|
|
- Smart polling: 30s idle → 3s cand ruleaza → auto-refresh tabela
|
|
- Last sync clickabil → jurnal detaliat
|
|
|
|
### Comenzi
|
|
- Filtru perioada: 3z / 7z / 30z / 3 luni / toate / custom
|
|
- Status pills cu conturi totale pe perioada (nu per-pagina)
|
|
- Cautare integrata in bara de filtre
|
|
- Coloana Client cu tooltip `▲` cand persoana livrare ≠ facturare
|
|
- Paginare sus + jos, selector rezultate per pagina (25/50/100/250)
|
|
|
|
### Mapari SKU
|
|
- Badge `✓ 100%` / `⚠ 80%` per grup SKU
|
|
- Filtru Complete / Incomplete
|
|
- Verificare duplicat SKU-CODMAT (409 cu optiune de restaurare)
|
|
|
|
### SKU-uri Lipsa
|
|
- Cautare dupa SKU sau nume produs
|
|
- Filtru Nerezolvate / Rezolvate / Toate cu conturi
|
|
- Re-scan cu progress inline si banner rezultat
|
|
|
|
---
|
|
|
|
## Fluxul de Import
|
|
|
|
```
|
|
1. gomag_client.py descarca comenzi GoMag API → JSON files
|
|
2. order_reader.py parseaza JSON-urile
|
|
3. validation_service.py valideaza SKU-uri contra ARTICOLE_TERTI + NOM_ARTICOLE
|
|
4. import_service.py creeaza/cauta partener in Oracle (shipping person = facturare)
|
|
5. PACK_IMPORT_COMENZI.importa_comanda_web() insereaza comanda in ROA
|
|
6. Rezultate salvate in SQLite (orders, sync_run_orders, order_items)
|
|
```
|
|
|
|
### Reguli Business
|
|
- **Persoana**: shipping name = persoana pe eticheta = beneficiarul facturii
|
|
- **Adresa**: cand billing ≠ shipping → adresa shipping pentru ambele (facturare + livrare)
|
|
- **SKU simplu**: gasit direct in NOM_ARTICOLE → nu se stocheaza in ARTICOLE_TERTI
|
|
- **SKU cu repackaging**: un SKU → CODMAT cu cantitate diferita
|
|
- **SKU set complex**: un SKU → multiple CODMAT-uri cu procente de pret
|
|
|
|
---
|
|
|
|
## Status Implementare
|
|
|
|
| Faza | Status | Descriere |
|
|
|------|--------|-----------|
|
|
| Phase 1: Database Foundation | Complet | ARTICOLE_TERTI, PACK_IMPORT_PARTENERI, PACK_IMPORT_COMENZI |
|
|
| Phase 2: Python Integration | Complet | gomag_client.py, sync_service.py |
|
|
| Phase 3-4: FastAPI Dashboard | Complet | UI responsive, smart polling, filter bar, paginare |
|
|
| Phase 5: Production | In Progress | Logging done, Auth + SMTP pending |
|
|
|
|
---
|
|
|
|
## Deploy Windows
|
|
|
|
### Instalare initiala
|
|
|
|
```powershell
|
|
# Ruleaza ca Administrator
|
|
.\deploy.ps1
|
|
```
|
|
|
|
Scriptul `deploy.ps1` face automat: git clone, venv, dependinte, detectare Oracle, `start.bat`, serviciu NSSM, configurare IIS reverse proxy.
|
|
|
|
### Update
|
|
|
|
```powershell
|
|
# Ca Administrator
|
|
.\update.ps1
|
|
```
|
|
|
|
### Configurare `.env` pe Windows
|
|
|
|
```ini
|
|
# api/.env — exemplu Windows
|
|
ORACLE_USER=VENDING
|
|
ORACLE_PASSWORD=****
|
|
ORACLE_DSN=ROA
|
|
TNS_ADMIN=C:\roa\instantclient_11_2_0_2
|
|
INSTANTCLIENTPATH=C:\app\Server\product\18.0.0\dbhomeXE\bin
|
|
```
|
|
|
|
**Important:**
|
|
- `TNS_ADMIN` = folderul care contine `tnsnames.ora` (NU fisierul in sine)
|
|
- `ORACLE_DSN` = alias-ul exact din `tnsnames.ora`
|
|
- `INSTANTCLIENTPATH` = calea catre Oracle bin (thick mode)
|
|
|
|
### Serviciu Windows (NSSM)
|
|
|
|
```powershell
|
|
nssm restart GoMagVending # restart
|
|
nssm status GoMagVending # status
|
|
nssm stop GoMagVending # stop
|
|
```
|
|
|
|
Loguri serviciu: `logs/service_stdout.log`, `logs/service_stderr.log`
|
|
Loguri aplicatie: `logs/sync_comenzi_*.log`
|
|
|
|
### Depanare SSH
|
|
|
|
```bash
|
|
# Conectare SSH (PowerShell remote, cheie publica)
|
|
ssh -p 22122 gomag@79.119.86.134
|
|
|
|
# Verificare .env
|
|
cmd /c type C:\gomag-vending\api\.env
|
|
|
|
# Test conexiune Oracle
|
|
C:\gomag-vending\venv\Scripts\python.exe -c "import oracledb, os; os.environ['TNS_ADMIN']='C:/roa/instantclient_11_2_0_2'; conn=oracledb.connect(user='VENDING', password='ROMFASTSOFT', dsn='ROA'); print('Connected!'); conn.close()"
|
|
|
|
# Verificare tnsnames.ora
|
|
cmd /c type C:\roa\instantclient_11_2_0_2\tnsnames.ora
|
|
|
|
# Verificare procese Python
|
|
Get-Process *python* | Select-Object Id,ProcessName,Path
|
|
|
|
# Verificare loguri recente
|
|
Get-ChildItem C:\gomag-vending\logs\*.log | Sort-Object LastWriteTime -Descending | Select-Object -First 3
|
|
```
|
|
|
|
**Nota SSH:** Userul `gomag` nu are drepturi de admin — `nssm restart` si `net stop/start` necesita PowerShell Administrator direct pe server.
|
|
|
|
### Probleme frecvente
|
|
|
|
| Eroare | Cauza | Solutie |
|
|
|--------|-------|---------|
|
|
| `ORA-12154: TNS:could not resolve` | `TNS_ADMIN` gresit sau `tnsnames.ora` nu contine alias-ul DSN | Verifica `TNS_ADMIN` in `.env` + alias in `tnsnames.ora` |
|
|
| `ORA-04088: LOGON_AUDIT_TRIGGER` + `Nu aveti licenta pentru PYTHON` | Trigger ROA blocheaza executabile nelicențiate | Adauga `python.exe` (calea completa) in ROASUPORT |
|
|
| `503 Service Unavailable` pe `/api/articles/search` | Oracle pool nu s-a initializat | Verifica logul `sync_comenzi_*.log` pentru eroarea exacta |
|
|
|
|
---
|
|
|
|
## WSL2 Note
|
|
|
|
- `uvicorn --reload` **nu functioneaza** pe `/mnt/e/` (WSL2 limitation) — restarta manual
|
|
- Serverul trebuie pornit din **project root**, nu din `api/`
|
|
- `JSON_OUTPUT_DIR` si `SQLITE_DB_PATH` sunt relative la project root
|