refactor: Use explicit Sage document type constants for enums, document listing, and transformation endpoints.
This commit is contained in:
parent
33843e031a
commit
b468c963c9
2 changed files with 42 additions and 64 deletions
85
api.py
85
api.py
|
|
@ -42,12 +42,13 @@ from sage_client import sage_client
|
|||
# ENUMS
|
||||
# =====================================================
|
||||
class TypeDocument(int, Enum):
|
||||
DEVIS = 0
|
||||
BON_LIVRAISON = 1
|
||||
BON_RETOUR = 2
|
||||
COMMANDE = 3
|
||||
PREPARATION = 4
|
||||
FACTURE = 5
|
||||
DEVIS = settings.SAGE_TYPE_DEVIS
|
||||
BON_COMMANDE = settings.SAGE_TYPE_BON_COMMANDE
|
||||
PREPARATION = settings.SAGE_TYPE_PREPARATION
|
||||
BON_LIVRAISON = settings.SAGE_TYPE_BON_LIVRAISON
|
||||
BON_RETOUR = settings.SAGE_TYPE_BON_RETOUR
|
||||
BON_AVOIR = settings.SAGE_TYPE_BON_AVOIR
|
||||
FACTURE = settings.SAGE_TYPE_FACTURE
|
||||
|
||||
|
||||
class StatutSignature(str, Enum):
|
||||
|
|
@ -515,11 +516,14 @@ async def lister_commandes(
|
|||
limit: int = Query(100, le=1000), statut: Optional[int] = Query(None)
|
||||
):
|
||||
"""
|
||||
📋 Liste toutes les commandes via gateway Windows
|
||||
📋 Liste toutes les commandes
|
||||
✅ CORRECTION : Filtre sur le type 10 (BON_COMMANDE)
|
||||
"""
|
||||
try:
|
||||
# ✅ APPEL VIA SAGE_CLIENT (HTTP vers Windows)
|
||||
commandes = sage_client.lister_commandes(limit=limit, statut=statut)
|
||||
# Le sage_client doit filtrer sur type=10, pas type=3
|
||||
commandes = sage_client.lister_documents_par_type(
|
||||
type_doc=settings.SAGE_TYPE_BON_COMMANDE, limit=limit, statut=statut # = 10
|
||||
)
|
||||
return commandes
|
||||
|
||||
except Exception as e:
|
||||
|
|
@ -530,25 +534,22 @@ async def lister_commandes(
|
|||
@app.post("/workflow/devis/{id}/to-commande", tags=["US-A2"])
|
||||
async def devis_vers_commande(id: str, session: AsyncSession = Depends(get_session)):
|
||||
"""
|
||||
🔧 Transformation Devis → Commande via gateway Windows
|
||||
|
||||
✅ CORRECTION: Envoie les valeurs numériques des enums, pas les noms
|
||||
🔧 Transformation Devis → Commande
|
||||
✅ CORRECTION : Utilise les VRAIS types Sage (0 → 10)
|
||||
"""
|
||||
try:
|
||||
# ✅ CRITIQUE: Utiliser .value pour obtenir l'entier
|
||||
resultat = sage_client.transformer_document(
|
||||
numero_source=id,
|
||||
type_source=TypeDocument.DEVIS.value, # ← .value = 0
|
||||
type_cible=TypeDocument.COMMANDE.value, # ← .value = 3
|
||||
type_source=settings.SAGE_TYPE_DEVIS, # = 0
|
||||
type_cible=settings.SAGE_TYPE_BON_COMMANDE, # = 10
|
||||
)
|
||||
|
||||
# Logger en DB
|
||||
workflow_log = WorkflowLog(
|
||||
id=str(uuid.uuid4()),
|
||||
document_source=id,
|
||||
type_source=TypeDocument.DEVIS,
|
||||
document_cible=resultat.get("document_cible", ""),
|
||||
type_cible=TypeDocument.COMMANDE,
|
||||
type_cible=TypeDocument.BON_COMMANDE,
|
||||
nb_lignes=resultat.get("nb_lignes", 0),
|
||||
date_transformation=datetime.now(),
|
||||
succes=True,
|
||||
|
|
@ -576,52 +577,20 @@ async def devis_vers_commande(id: str, session: AsyncSession = Depends(get_sessi
|
|||
@app.post("/workflow/commande/{id}/to-facture", tags=["US-A2"])
|
||||
async def commande_vers_facture(id: str, session: AsyncSession = Depends(get_session)):
|
||||
"""
|
||||
🔧 Transformation Commande → Facture via gateway Windows
|
||||
|
||||
✅ CORRECTION: Envoie les valeurs numériques
|
||||
🔧 Transformation Commande → Facture
|
||||
✅ CORRECTION : Utilise les VRAIS types Sage (10 → 60)
|
||||
"""
|
||||
try:
|
||||
resultat = sage_client.transformer_document(
|
||||
numero_source=id,
|
||||
type_source=TypeDocument.COMMANDE.value, # ← 3
|
||||
type_cible=TypeDocument.FACTURE.value, # ← 5
|
||||
type_source=settings.SAGE_TYPE_BON_COMMANDE, # = 10
|
||||
type_cible=settings.SAGE_TYPE_FACTURE, # = 60
|
||||
)
|
||||
|
||||
workflow_log = WorkflowLog(
|
||||
id=str(uuid.uuid4()),
|
||||
document_source=id,
|
||||
type_source=TypeDocument.COMMANDE,
|
||||
document_cible=resultat.get("document_cible", ""),
|
||||
type_cible=TypeDocument.FACTURE,
|
||||
nb_lignes=resultat.get("nb_lignes", 0),
|
||||
date_transformation=datetime.now(),
|
||||
succes=True,
|
||||
)
|
||||
|
||||
session.add(workflow_log)
|
||||
await session.commit()
|
||||
|
||||
return resultat
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Erreur transformation: {e}")
|
||||
raise HTTPException(500, str(e))
|
||||
|
||||
|
||||
@app.post("/workflow/commande/{id}/to-facture", tags=["US-A2"])
|
||||
async def commande_vers_facture(id: str, session: AsyncSession = Depends(get_session)):
|
||||
"""🔧 Transformation Commande → Facture via gateway Windows"""
|
||||
try:
|
||||
resultat = sage_client.transformer_document(
|
||||
numero_source=id,
|
||||
type_source=TypeDocument.COMMANDE,
|
||||
type_cible=TypeDocument.FACTURE,
|
||||
)
|
||||
|
||||
workflow_log = WorkflowLog(
|
||||
id=str(uuid.uuid4()),
|
||||
document_source=id,
|
||||
type_source=TypeDocument.COMMANDE,
|
||||
type_source=TypeDocument.BON_COMMANDE,
|
||||
document_cible=resultat.get("document_cible", ""),
|
||||
type_cible=TypeDocument.FACTURE,
|
||||
nb_lignes=resultat.get("nb_lignes", 0),
|
||||
|
|
@ -1132,11 +1101,13 @@ async def lister_factures(
|
|||
limit: int = Query(100, le=1000), statut: Optional[int] = Query(None)
|
||||
):
|
||||
"""
|
||||
📋 Liste toutes les factures via gateway Windows
|
||||
📋 Liste toutes les factures
|
||||
✅ CORRECTION : Filtre sur le type 60 (FACTURE)
|
||||
"""
|
||||
try:
|
||||
# ✅ APPEL VIA SAGE_CLIENT (HTTP vers Windows)
|
||||
factures = sage_client.lister_factures(limit=limit, statut=statut)
|
||||
factures = sage_client.lister_documents_par_type(
|
||||
type_doc=settings.SAGE_TYPE_FACTURE, limit=limit, statut=statut # = 60
|
||||
)
|
||||
return factures
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
21
config.py
21
config.py
|
|
@ -1,14 +1,20 @@
|
|||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
from typing import List
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
case_sensitive=False,
|
||||
extra="ignore"
|
||||
env_file=".env", env_file_encoding="utf-8", case_sensitive=False, extra="ignore"
|
||||
)
|
||||
|
||||
SAGE_TYPE_DEVIS: int = 0
|
||||
SAGE_TYPE_BON_COMMANDE: int = 10
|
||||
SAGE_TYPE_PREPARATION: int = 20
|
||||
SAGE_TYPE_BON_LIVRAISON: int = 30
|
||||
SAGE_TYPE_BON_RETOUR: int = 40
|
||||
SAGE_TYPE_BON_AVOIR: int = 50
|
||||
SAGE_TYPE_FACTURE: int = 60
|
||||
|
||||
# === Sage Gateway (Windows) ===
|
||||
sage_gateway_url: str
|
||||
sage_gateway_token: str
|
||||
|
|
@ -31,13 +37,14 @@ class Settings(BaseSettings):
|
|||
api_host: str
|
||||
api_port: int
|
||||
api_reload: bool = False
|
||||
|
||||
|
||||
# === Email Queue ===
|
||||
max_email_workers: int = 3
|
||||
max_retry_attempts: int = 3
|
||||
retry_delay_seconds: int = 60
|
||||
|
||||
|
||||
# === CORS ===
|
||||
cors_origins: List[str] = ["*"]
|
||||
|
||||
settings = Settings()
|
||||
|
||||
settings = Settings()
|
||||
|
|
|
|||
Loading…
Reference in a new issue