fix(api): normalize document types and fix status change validation
This commit is contained in:
parent
e85c6560be
commit
6eba416f72
1 changed files with 27 additions and 7 deletions
30
api.py
30
api.py
|
|
@ -830,30 +830,38 @@ async def changer_statut_document(
|
|||
):
|
||||
document_type_sql = None
|
||||
document_type_code = None
|
||||
type_doc_normalized = None
|
||||
|
||||
try:
|
||||
match type_doc:
|
||||
case 0:
|
||||
document_type_sql = TypeDocumentSQL.DEVIS
|
||||
document_type_code = TypeDocument.DEVIS
|
||||
type_doc_normalized = 0
|
||||
case 10 | 1:
|
||||
document_type_sql = TypeDocumentSQL.BON_COMMANDE
|
||||
document_type_code = TypeDocument.BON_COMMANDE
|
||||
type_doc_normalized = 10
|
||||
case 20 | 2:
|
||||
document_type_sql = TypeDocumentSQL.PREPARATION
|
||||
document_type_code = TypeDocument.PREPARATION
|
||||
type_doc_normalized = 20
|
||||
case 30 | 3:
|
||||
document_type_sql = TypeDocumentSQL.BON_LIVRAISON
|
||||
document_type_code = TypeDocument.BON_LIVRAISON
|
||||
type_doc_normalized = 30
|
||||
case 40 | 4:
|
||||
document_type_sql = TypeDocumentSQL.BON_RETOUR
|
||||
document_type_code = TypeDocument.BON_RETOUR
|
||||
type_doc_normalized = 40
|
||||
case 50 | 5:
|
||||
document_type_sql = TypeDocumentSQL.BON_AVOIR
|
||||
document_type_code = TypeDocument.BON_AVOIR
|
||||
type_doc_normalized = 50
|
||||
case 60 | 6:
|
||||
document_type_sql = TypeDocumentSQL.FACTURE
|
||||
document_type_code = TypeDocument.FACTURE
|
||||
type_doc_normalized = 60
|
||||
case _:
|
||||
raise HTTPException(
|
||||
400,
|
||||
|
|
@ -879,23 +887,35 @@ async def changer_statut_document(
|
|||
case 10 | 1 | 20 | 2 | 30 | 3 | 40 | 4 | 50 | 5 | 60 | 6:
|
||||
if statut_actuel >= 2:
|
||||
type_names = {
|
||||
10: "la commande", 20: "la préparation", 30: "la livraison",
|
||||
40: "le retour", 50: "l'avoir", 60: "la facture"
|
||||
10: "la commande", 1: "la commande",
|
||||
20: "la préparation", 2: "la préparation",
|
||||
30: "la livraison", 3: "la livraison",
|
||||
40: "le retour", 4: "le retour",
|
||||
50: "l'avoir", 5: "l'avoir",
|
||||
60: "la facture", 6: "la facture"
|
||||
}
|
||||
raise HTTPException(
|
||||
400,
|
||||
f"Le document {numero} ({type_names.get(document_type_sql, 'document')}) "
|
||||
f"Le document {numero} ({type_names.get(type_doc, 'document')}) "
|
||||
f"ne peut plus changer de statut (statut actuel ≥ 2)",
|
||||
)
|
||||
|
||||
resultat = sage_client.changer_statut_document(numero,document_type_code, nouveau_statut)
|
||||
# CORRECTION ICI : utiliser les bons paramètres dans le bon ordre
|
||||
# Et convertir l'enum en int avec .value si nécessaire
|
||||
document_type_int = document_type_code.value if hasattr(document_type_code, 'value') else type_doc_normalized
|
||||
|
||||
resultat = sage_client.changer_statut_document(
|
||||
document_type_code=document_type_int,
|
||||
numero=numero,
|
||||
nouveau_statut=nouveau_statut
|
||||
)
|
||||
|
||||
logger.info(f"Statut document {numero} changé: {statut_actuel} → {nouveau_statut}")
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"document_id": numero,
|
||||
"type_document_code": document_type_code,
|
||||
"type_document_code": document_type_int,
|
||||
"type_document_sql": str(document_type_sql),
|
||||
"statut_ancien": resultat.get("statut_ancien", statut_actuel),
|
||||
"statut_nouveau": resultat.get("statut_nouveau", nouveau_statut),
|
||||
|
|
|
|||
Loading…
Reference in a new issue