updated devis to command logics transformation

This commit is contained in:
Fanilo-Nantenaina 2025-11-28 05:54:25 +03:00
parent c0327f1890
commit 33843e031a

47
api.py
View file

@ -529,13 +529,17 @@ 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"""
"""
🔧 Transformation Devis Commande via gateway Windows
CORRECTION: Envoie les valeurs numériques des enums, pas les noms
"""
try:
# Appel HTTP vers Windows
# ✅ CRITIQUE: Utiliser .value pour obtenir l'entier
resultat = sage_client.transformer_document(
numero_source=id,
type_source=TypeDocument.DEVIS,
type_cible=TypeDocument.COMMANDE,
type_source=TypeDocument.DEVIS.value, # ← .value = 0
type_cible=TypeDocument.COMMANDE.value, # ← .value = 3
)
# Logger en DB
@ -569,6 +573,41 @@ async def devis_vers_commande(id: str, session: AsyncSession = Depends(get_sessi
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
CORRECTION: Envoie les valeurs numériques
"""
try:
resultat = sage_client.transformer_document(
numero_source=id,
type_source=TypeDocument.COMMANDE.value, # ← 3
type_cible=TypeDocument.FACTURE.value, # ← 5
)
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"""