refactor: Use specialized Sage client methods for listing commands and invoices, and enhance the document transformation response.
This commit is contained in:
parent
b468c963c9
commit
3f8238f674
2 changed files with 31 additions and 19 deletions
34
api.py
34
api.py
|
|
@ -516,14 +516,13 @@ async def lister_commandes(
|
||||||
limit: int = Query(100, le=1000), statut: Optional[int] = Query(None)
|
limit: int = Query(100, le=1000), statut: Optional[int] = Query(None)
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
📋 Liste toutes les commandes
|
📋 Liste toutes les commandes via gateway Windows
|
||||||
✅ CORRECTION : Filtre sur le type 10 (BON_COMMANDE)
|
|
||||||
|
✅ CORRECTION : Utilise sage_client.lister_commandes() qui existe déjà
|
||||||
|
Le filtrage sur type 10 est fait côté Windows dans main.py
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Le sage_client doit filtrer sur type=10, pas type=3
|
commandes = sage_client.lister_commandes(limit=limit, statut=statut)
|
||||||
commandes = sage_client.lister_documents_par_type(
|
|
||||||
type_doc=settings.SAGE_TYPE_BON_COMMANDE, limit=limit, statut=statut # = 10
|
|
||||||
)
|
|
||||||
return commandes
|
return commandes
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -578,7 +577,7 @@ async def devis_vers_commande(id: str, session: AsyncSession = Depends(get_sessi
|
||||||
async def commande_vers_facture(id: str, session: AsyncSession = Depends(get_session)):
|
async def commande_vers_facture(id: str, session: AsyncSession = Depends(get_session)):
|
||||||
"""
|
"""
|
||||||
🔧 Transformation Commande → Facture
|
🔧 Transformation Commande → Facture
|
||||||
✅ CORRECTION : Utilise les VRAIS types Sage (10 → 60)
|
✅ Utilise les VRAIS types Sage (10 → 60)
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
resultat = sage_client.transformer_document(
|
resultat = sage_client.transformer_document(
|
||||||
|
|
@ -601,7 +600,16 @@ async def commande_vers_facture(id: str, session: AsyncSession = Depends(get_ses
|
||||||
session.add(workflow_log)
|
session.add(workflow_log)
|
||||||
await session.commit()
|
await session.commit()
|
||||||
|
|
||||||
return resultat
|
logger.info(
|
||||||
|
f"✅ Transformation: Commande {id} → Facture {resultat['document_cible']}"
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"document_source": id,
|
||||||
|
"document_cible": resultat["document_cible"],
|
||||||
|
"nb_lignes": resultat["nb_lignes"],
|
||||||
|
}
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Erreur transformation: {e}")
|
logger.error(f"Erreur transformation: {e}")
|
||||||
|
|
@ -1101,13 +1109,13 @@ async def lister_factures(
|
||||||
limit: int = Query(100, le=1000), statut: Optional[int] = Query(None)
|
limit: int = Query(100, le=1000), statut: Optional[int] = Query(None)
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
📋 Liste toutes les factures
|
📋 Liste toutes les factures via gateway Windows
|
||||||
✅ CORRECTION : Filtre sur le type 60 (FACTURE)
|
|
||||||
|
✅ CORRECTION : Utilise sage_client.lister_factures() qui existe déjà
|
||||||
|
Le filtrage sur type 60 est fait côté Windows dans main.py
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
factures = sage_client.lister_documents_par_type(
|
factures = sage_client.lister_factures(limit=limit, statut=statut)
|
||||||
type_doc=settings.SAGE_TYPE_FACTURE, limit=limit, statut=statut # = 60
|
|
||||||
)
|
|
||||||
return factures
|
return factures
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ logger = logging.getLogger(__name__)
|
||||||
class SageGatewayClient:
|
class SageGatewayClient:
|
||||||
"""
|
"""
|
||||||
Client HTTP pour communiquer avec la gateway Sage Windows
|
Client HTTP pour communiquer avec la gateway Sage Windows
|
||||||
✅ VERSION CORRIGÉE
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
@ -121,7 +120,7 @@ class SageGatewayClient:
|
||||||
params={
|
params={
|
||||||
"numero": numero,
|
"numero": numero,
|
||||||
"nouveau_statut": nouveau_statut,
|
"nouveau_statut": nouveau_statut,
|
||||||
}, # ← QUERY PARAMS
|
},
|
||||||
headers=self.headers,
|
headers=self.headers,
|
||||||
timeout=self.timeout,
|
timeout=self.timeout,
|
||||||
)
|
)
|
||||||
|
|
@ -149,13 +148,13 @@ class SageGatewayClient:
|
||||||
try:
|
try:
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
f"{self.url}/sage/documents/transform",
|
f"{self.url}/sage/documents/transform",
|
||||||
params={ # ← QUERY PARAMS
|
params={
|
||||||
"numero_source": numero_source,
|
"numero_source": numero_source,
|
||||||
"type_source": type_source,
|
"type_source": type_source,
|
||||||
"type_cible": type_cible,
|
"type_cible": type_cible,
|
||||||
},
|
},
|
||||||
headers=self.headers,
|
headers=self.headers,
|
||||||
timeout=60, # Timeout plus long pour transformation
|
timeout=60,
|
||||||
)
|
)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
return r.json().get("data", {})
|
return r.json().get("data", {})
|
||||||
|
|
@ -184,7 +183,9 @@ class SageGatewayClient:
|
||||||
def lister_commandes(
|
def lister_commandes(
|
||||||
self, limit: int = 100, statut: Optional[int] = None
|
self, limit: int = 100, statut: Optional[int] = None
|
||||||
) -> List[Dict]:
|
) -> List[Dict]:
|
||||||
"""Liste toutes les commandes"""
|
"""
|
||||||
|
Utilise l'endpoint /sage/commandes/list qui filtre déjà sur type 10
|
||||||
|
"""
|
||||||
payload = {"limit": limit}
|
payload = {"limit": limit}
|
||||||
if statut is not None:
|
if statut is not None:
|
||||||
payload["statut"] = statut
|
payload["statut"] = statut
|
||||||
|
|
@ -196,7 +197,10 @@ class SageGatewayClient:
|
||||||
def lister_factures(
|
def lister_factures(
|
||||||
self, limit: int = 100, statut: Optional[int] = None
|
self, limit: int = 100, statut: Optional[int] = None
|
||||||
) -> List[Dict]:
|
) -> List[Dict]:
|
||||||
"""Liste toutes les factures"""
|
"""
|
||||||
|
✅ Liste toutes les factures
|
||||||
|
Utilise l'endpoint /sage/factures/list qui filtre déjà sur type 60
|
||||||
|
"""
|
||||||
payload = {"limit": limit}
|
payload = {"limit": limit}
|
||||||
if statut is not None:
|
if statut is not None:
|
||||||
payload["statut"] = statut
|
payload["statut"] = statut
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue