feat(documents): enhance document status change handling
This commit is contained in:
parent
c89db29963
commit
e85c6560be
3 changed files with 35 additions and 24 deletions
54
api.py
54
api.py
|
|
@ -828,31 +828,39 @@ async def changer_statut_document(
|
|||
..., ge=0, le=6, description="0=Saisi, 1=Confirmé, 2=Accepté"
|
||||
),
|
||||
):
|
||||
document_type = 0
|
||||
document_type_sql = None
|
||||
document_type_code = None
|
||||
|
||||
try:
|
||||
match type_doc:
|
||||
case 0:
|
||||
document_type = TypeDocumentSQL.DEVIS
|
||||
document_type_sql = TypeDocumentSQL.DEVIS
|
||||
document_type_code = TypeDocument.DEVIS
|
||||
case 10 | 1:
|
||||
document_type = TypeDocumentSQL.BON_COMMANDE
|
||||
document_type_sql = TypeDocumentSQL.BON_COMMANDE
|
||||
document_type_code = TypeDocument.BON_COMMANDE
|
||||
case 20 | 2:
|
||||
document_type = TypeDocumentSQL.PREPARATION
|
||||
document_type_sql = TypeDocumentSQL.PREPARATION
|
||||
document_type_code = TypeDocument.PREPARATION
|
||||
case 30 | 3:
|
||||
document_type = TypeDocumentSQL.BON_LIVRAISON
|
||||
document_type_sql = TypeDocumentSQL.BON_LIVRAISON
|
||||
document_type_code = TypeDocument.BON_LIVRAISON
|
||||
case 40 | 4:
|
||||
document_type = TypeDocumentSQL.BON_RETOUR
|
||||
document_type_sql = TypeDocumentSQL.BON_RETOUR
|
||||
document_type_code = TypeDocument.BON_RETOUR
|
||||
case 50 | 5:
|
||||
document_type = TypeDocumentSQL.BON_AVOIR
|
||||
document_type_sql = TypeDocumentSQL.BON_AVOIR
|
||||
document_type_code = TypeDocument.BON_AVOIR
|
||||
case 60 | 6:
|
||||
document_type = TypeDocumentSQL.FACTURE
|
||||
document_type_sql = TypeDocumentSQL.FACTURE
|
||||
document_type_code = TypeDocument.FACTURE
|
||||
case _:
|
||||
raise HTTPException(
|
||||
400,
|
||||
f"Type de document invalide: {type_doc}. "
|
||||
f"Types valides: {list(settings.__dict__.values())}",
|
||||
f"Type de document invalide: {type_doc}",
|
||||
)
|
||||
|
||||
document_existant = sage_client.lire_document(numero, document_type)
|
||||
|
||||
document_existant = sage_client.lire_document(numero, document_type_sql)
|
||||
if not document_existant:
|
||||
raise HTTPException(404, f"Document {numero} introuvable")
|
||||
|
||||
|
|
@ -868,25 +876,27 @@ async def changer_statut_document(
|
|||
f"et ne peut plus changer de statut",
|
||||
)
|
||||
|
||||
case 10 | 1 | 30 | 3 | 60 | 6 | 50 | 5:
|
||||
case 10 | 1 | 20 | 2 | 30 | 3 | 40 |4 |50 | 5 | 60 | 6:
|
||||
if statut_actuel >= 2:
|
||||
type_names = {10: "commande", 1: "commande", 30: "livraison",
|
||||
3: "livraison", 60: "facture", 6: "facture",
|
||||
50: "avoir", 5: "avoir"}
|
||||
type_names = {
|
||||
10: "la commande", 20: "la préparation", 30: "la livraison",
|
||||
40: "le retour", 50: "l'avoir", 60: "la facture"
|
||||
}
|
||||
raise HTTPException(
|
||||
400,
|
||||
f"Le document {numero} ({type_names.get(type_doc, 'document')}) "
|
||||
f"ne peut plus changer de statut (statut actuel: {statut_actuel})",
|
||||
f"Le document {numero} ({type_names.get(document_type_sql, 'document')}) "
|
||||
f"ne peut plus changer de statut (statut actuel ≥ 2)",
|
||||
)
|
||||
|
||||
resultat = sage_client.changer_statut_document(numero, nouveau_statut)
|
||||
|
||||
resultat = sage_client.changer_statut_document(numero,document_type_code, nouveau_statut)
|
||||
|
||||
logger.info(f"Statut document {numero} changé: {statut_actuel} → {nouveau_statut}")
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"document_id": numero,
|
||||
"type_document": type_doc,
|
||||
"type_document_code": document_type_code,
|
||||
"type_document_sql": str(document_type_sql),
|
||||
"statut_ancien": resultat.get("statut_ancien", statut_actuel),
|
||||
"statut_nouveau": resultat.get("statut_nouveau", nouveau_statut),
|
||||
"message": f"Statut mis à jour: {statut_actuel} → {nouveau_statut}",
|
||||
|
|
@ -897,7 +907,7 @@ async def changer_statut_document(
|
|||
except Exception as e:
|
||||
logger.error(f"Erreur changement statut document {numero}: {e}")
|
||||
raise HTTPException(500, str(e))
|
||||
|
||||
|
||||
@app.get("/commandes/{id}", tags=["Commandes"])
|
||||
async def lire_commande(id: str):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -94,12 +94,13 @@ class SageGatewayClient:
|
|||
payload["statut"] = statut
|
||||
return self._post("/sage/devis/list", payload).get("data", [])
|
||||
|
||||
def changer_statut_document(self, numero: str, nouveau_statut: int) -> Dict:
|
||||
def changer_statut_document(self, document_type_code: int, numero: str, nouveau_statut: int) -> Dict:
|
||||
try:
|
||||
r = requests.post(
|
||||
f"{self.url}/sage/document/statut",
|
||||
params={
|
||||
"numero": numero,
|
||||
"type_doc": document_type_code,
|
||||
"nouveau_statut": nouveau_statut,
|
||||
},
|
||||
headers=self.headers,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
from config import settings
|
||||
from enum import Enum, IntEnum
|
||||
from enum import Enum
|
||||
|
||||
class TypeDocument(int, Enum):
|
||||
DEVIS = settings.SAGE_TYPE_DEVIS
|
||||
|
|
|
|||
Loading…
Reference in a new issue