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
48
api.py
48
api.py
|
|
@ -828,31 +828,39 @@ async def changer_statut_document(
|
||||||
..., ge=0, le=6, description="0=Saisi, 1=Confirmé, 2=Accepté"
|
..., ge=0, le=6, description="0=Saisi, 1=Confirmé, 2=Accepté"
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
document_type = 0
|
document_type_sql = None
|
||||||
|
document_type_code = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
match type_doc:
|
match type_doc:
|
||||||
case 0:
|
case 0:
|
||||||
document_type = TypeDocumentSQL.DEVIS
|
document_type_sql = TypeDocumentSQL.DEVIS
|
||||||
|
document_type_code = TypeDocument.DEVIS
|
||||||
case 10 | 1:
|
case 10 | 1:
|
||||||
document_type = TypeDocumentSQL.BON_COMMANDE
|
document_type_sql = TypeDocumentSQL.BON_COMMANDE
|
||||||
|
document_type_code = TypeDocument.BON_COMMANDE
|
||||||
case 20 | 2:
|
case 20 | 2:
|
||||||
document_type = TypeDocumentSQL.PREPARATION
|
document_type_sql = TypeDocumentSQL.PREPARATION
|
||||||
|
document_type_code = TypeDocument.PREPARATION
|
||||||
case 30 | 3:
|
case 30 | 3:
|
||||||
document_type = TypeDocumentSQL.BON_LIVRAISON
|
document_type_sql = TypeDocumentSQL.BON_LIVRAISON
|
||||||
|
document_type_code = TypeDocument.BON_LIVRAISON
|
||||||
case 40 | 4:
|
case 40 | 4:
|
||||||
document_type = TypeDocumentSQL.BON_RETOUR
|
document_type_sql = TypeDocumentSQL.BON_RETOUR
|
||||||
|
document_type_code = TypeDocument.BON_RETOUR
|
||||||
case 50 | 5:
|
case 50 | 5:
|
||||||
document_type = TypeDocumentSQL.BON_AVOIR
|
document_type_sql = TypeDocumentSQL.BON_AVOIR
|
||||||
|
document_type_code = TypeDocument.BON_AVOIR
|
||||||
case 60 | 6:
|
case 60 | 6:
|
||||||
document_type = TypeDocumentSQL.FACTURE
|
document_type_sql = TypeDocumentSQL.FACTURE
|
||||||
|
document_type_code = TypeDocument.FACTURE
|
||||||
case _:
|
case _:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
400,
|
400,
|
||||||
f"Type de document invalide: {type_doc}. "
|
f"Type de document invalide: {type_doc}",
|
||||||
f"Types valides: {list(settings.__dict__.values())}",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
document_existant = sage_client.lire_document(numero, document_type)
|
document_existant = sage_client.lire_document(numero, document_type_sql)
|
||||||
if not document_existant:
|
if not document_existant:
|
||||||
raise HTTPException(404, f"Document {numero} introuvable")
|
raise HTTPException(404, f"Document {numero} introuvable")
|
||||||
|
|
||||||
|
|
@ -868,25 +876,27 @@ async def changer_statut_document(
|
||||||
f"et ne peut plus changer de statut",
|
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:
|
if statut_actuel >= 2:
|
||||||
type_names = {10: "commande", 1: "commande", 30: "livraison",
|
type_names = {
|
||||||
3: "livraison", 60: "facture", 6: "facture",
|
10: "la commande", 20: "la préparation", 30: "la livraison",
|
||||||
50: "avoir", 5: "avoir"}
|
40: "le retour", 50: "l'avoir", 60: "la facture"
|
||||||
|
}
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
400,
|
400,
|
||||||
f"Le document {numero} ({type_names.get(type_doc, 'document')}) "
|
f"Le document {numero} ({type_names.get(document_type_sql, 'document')}) "
|
||||||
f"ne peut plus changer de statut (statut actuel: {statut_actuel})",
|
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}")
|
logger.info(f"Statut document {numero} changé: {statut_actuel} → {nouveau_statut}")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"document_id": numero,
|
"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_ancien": resultat.get("statut_ancien", statut_actuel),
|
||||||
"statut_nouveau": resultat.get("statut_nouveau", nouveau_statut),
|
"statut_nouveau": resultat.get("statut_nouveau", nouveau_statut),
|
||||||
"message": f"Statut mis à jour: {statut_actuel} → {nouveau_statut}",
|
"message": f"Statut mis à jour: {statut_actuel} → {nouveau_statut}",
|
||||||
|
|
|
||||||
|
|
@ -94,12 +94,13 @@ class SageGatewayClient:
|
||||||
payload["statut"] = statut
|
payload["statut"] = statut
|
||||||
return self._post("/sage/devis/list", payload).get("data", [])
|
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:
|
try:
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
f"{self.url}/sage/document/statut",
|
f"{self.url}/sage/document/statut",
|
||||||
params={
|
params={
|
||||||
"numero": numero,
|
"numero": numero,
|
||||||
|
"type_doc": document_type_code,
|
||||||
"nouveau_statut": nouveau_statut,
|
"nouveau_statut": nouveau_statut,
|
||||||
},
|
},
|
||||||
headers=self.headers,
|
headers=self.headers,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
from config import settings
|
from config import settings
|
||||||
from enum import Enum, IntEnum
|
from enum import Enum
|
||||||
|
|
||||||
class TypeDocument(int, Enum):
|
class TypeDocument(int, Enum):
|
||||||
DEVIS = settings.SAGE_TYPE_DEVIS
|
DEVIS = settings.SAGE_TYPE_DEVIS
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue