fix: Use query parameters for changing quote status and transforming documents, and remove "NOUVEAU" tags from docstrings.
This commit is contained in:
parent
b11e161e7f
commit
c0327f1890
1 changed files with 45 additions and 27 deletions
|
|
@ -9,7 +9,7 @@ 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 COMPLÈTE avec toutes les routes nécessaires
|
✅ VERSION CORRIGÉE
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
@ -104,12 +104,7 @@ class SageGatewayClient:
|
||||||
inclure_lignes: bool = True,
|
inclure_lignes: bool = True,
|
||||||
) -> List[Dict]:
|
) -> List[Dict]:
|
||||||
"""
|
"""
|
||||||
✅ NOUVEAU: Liste tous les devis avec filtres
|
✅ Liste tous les devis avec filtres
|
||||||
|
|
||||||
Args:
|
|
||||||
limit: Nombre max de devis
|
|
||||||
statut: Filtre par statut (optionnel)
|
|
||||||
inclure_lignes: Si True, charge les lignes de chaque devis (par défaut: True)
|
|
||||||
"""
|
"""
|
||||||
payload = {"limit": limit, "inclure_lignes": inclure_lignes}
|
payload = {"limit": limit, "inclure_lignes": inclure_lignes}
|
||||||
if statut is not None:
|
if statut is not None:
|
||||||
|
|
@ -117,10 +112,24 @@ class SageGatewayClient:
|
||||||
return self._post("/sage/devis/list", payload).get("data", [])
|
return self._post("/sage/devis/list", payload).get("data", [])
|
||||||
|
|
||||||
def changer_statut_devis(self, numero: str, nouveau_statut: int) -> Dict:
|
def changer_statut_devis(self, numero: str, nouveau_statut: int) -> Dict:
|
||||||
"""✅ NOUVEAU: Change le statut d'un devis"""
|
"""
|
||||||
return self._post(
|
✅ CORRECTION: Utilise query params au lieu du body
|
||||||
"/sage/devis/statut", {"numero": numero, "nouveau_statut": nouveau_statut}
|
"""
|
||||||
).get("data", {})
|
try:
|
||||||
|
r = requests.post(
|
||||||
|
f"{self.url}/sage/devis/statut",
|
||||||
|
params={
|
||||||
|
"numero": numero,
|
||||||
|
"nouveau_statut": nouveau_statut,
|
||||||
|
}, # ← QUERY PARAMS
|
||||||
|
headers=self.headers,
|
||||||
|
timeout=self.timeout,
|
||||||
|
)
|
||||||
|
r.raise_for_status()
|
||||||
|
return r.json().get("data", {})
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
logger.error(f"❌ Erreur changement statut: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
# =====================================================
|
# =====================================================
|
||||||
# DOCUMENTS GÉNÉRIQUES
|
# DOCUMENTS GÉNÉRIQUES
|
||||||
|
|
@ -134,15 +143,25 @@ class SageGatewayClient:
|
||||||
def transformer_document(
|
def transformer_document(
|
||||||
self, numero_source: str, type_source: int, type_cible: int
|
self, numero_source: str, type_source: int, type_cible: int
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
"""Transformation de document (devis → commande → facture)"""
|
"""
|
||||||
return self._post(
|
✅ CORRECTION: Utilise query params pour la transformation
|
||||||
"/sage/documents/transform",
|
"""
|
||||||
{
|
try:
|
||||||
|
r = requests.post(
|
||||||
|
f"{self.url}/sage/documents/transform",
|
||||||
|
params={ # ← QUERY 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,
|
||||||
},
|
},
|
||||||
).get("data", {})
|
headers=self.headers,
|
||||||
|
timeout=60, # Timeout plus long pour transformation
|
||||||
|
)
|
||||||
|
r.raise_for_status()
|
||||||
|
return r.json().get("data", {})
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
logger.error(f"❌ Erreur transformation: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
def mettre_a_jour_champ_libre(
|
def mettre_a_jour_champ_libre(
|
||||||
self, doc_id: str, type_doc: int, nom_champ: str, valeur: str
|
self, doc_id: str, type_doc: int, nom_champ: str, valeur: str
|
||||||
|
|
@ -165,7 +184,7 @@ 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]:
|
||||||
"""✅ NOUVEAU: Liste toutes les commandes"""
|
"""Liste toutes les commandes"""
|
||||||
payload = {"limit": limit}
|
payload = {"limit": limit}
|
||||||
if statut is not None:
|
if statut is not None:
|
||||||
payload["statut"] = statut
|
payload["statut"] = statut
|
||||||
|
|
@ -177,14 +196,14 @@ 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]:
|
||||||
"""✅ NOUVEAU: Liste toutes les factures"""
|
"""Liste toutes les factures"""
|
||||||
payload = {"limit": limit}
|
payload = {"limit": limit}
|
||||||
if statut is not None:
|
if statut is not None:
|
||||||
payload["statut"] = statut
|
payload["statut"] = statut
|
||||||
return self._post("/sage/factures/list", payload).get("data", [])
|
return self._post("/sage/factures/list", payload).get("data", [])
|
||||||
|
|
||||||
def mettre_a_jour_derniere_relance(self, doc_id: str, type_doc: int) -> bool:
|
def mettre_a_jour_derniere_relance(self, doc_id: str, type_doc: int) -> bool:
|
||||||
"""✅ NOUVEAU: Met à jour le champ 'Dernière relance' d'une facture"""
|
"""Met à jour le champ 'Dernière relance' d'une facture"""
|
||||||
resp = self._post(
|
resp = self._post(
|
||||||
"/sage/documents/derniere-relance", {"doc_id": doc_id, "type_doc": type_doc}
|
"/sage/documents/derniere-relance", {"doc_id": doc_id, "type_doc": type_doc}
|
||||||
)
|
)
|
||||||
|
|
@ -201,7 +220,7 @@ class SageGatewayClient:
|
||||||
# REMISES (US-A5)
|
# REMISES (US-A5)
|
||||||
# =====================================================
|
# =====================================================
|
||||||
def lire_remise_max_client(self, code_client: str) -> float:
|
def lire_remise_max_client(self, code_client: str) -> float:
|
||||||
"""✅ NOUVEAU: Récupère la remise max autorisée pour un client"""
|
"""Récupère la remise max autorisée pour un client"""
|
||||||
result = self._post("/sage/client/remise-max", {"code": code_client})
|
result = self._post("/sage/client/remise-max", {"code": code_client})
|
||||||
return result.get("data", {}).get("remise_max", 10.0)
|
return result.get("data", {}).get("remise_max", 10.0)
|
||||||
|
|
||||||
|
|
@ -209,17 +228,16 @@ class SageGatewayClient:
|
||||||
# GÉNÉRATION PDF (pour email_queue)
|
# GÉNÉRATION PDF (pour email_queue)
|
||||||
# =====================================================
|
# =====================================================
|
||||||
def generer_pdf_document(self, doc_id: str, type_doc: int) -> bytes:
|
def generer_pdf_document(self, doc_id: str, type_doc: int) -> bytes:
|
||||||
"""✅ NOUVEAU: Génère le PDF d'un document via la gateway Windows"""
|
"""Génère le PDF d'un document via la gateway Windows"""
|
||||||
try:
|
try:
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
f"{self.url}/sage/documents/generate-pdf",
|
f"{self.url}/sage/documents/generate-pdf",
|
||||||
json={"doc_id": doc_id, "type_doc": type_doc},
|
json={"doc_id": doc_id, "type_doc": type_doc},
|
||||||
headers=self.headers,
|
headers=self.headers,
|
||||||
timeout=60, # Timeout plus long pour génération PDF
|
timeout=60,
|
||||||
)
|
)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
|
||||||
# Le PDF est retourné en base64 dans la réponse JSON
|
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
response_data = r.json()
|
response_data = r.json()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue