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:
|
||||
"""
|
||||
Client HTTP pour communiquer avec la gateway Sage Windows
|
||||
✅ VERSION COMPLÈTE avec toutes les routes nécessaires
|
||||
✅ VERSION CORRIGÉE
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
|
|
@ -104,12 +104,7 @@ class SageGatewayClient:
|
|||
inclure_lignes: bool = True,
|
||||
) -> List[Dict]:
|
||||
"""
|
||||
✅ NOUVEAU: 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)
|
||||
✅ Liste tous les devis avec filtres
|
||||
"""
|
||||
payload = {"limit": limit, "inclure_lignes": inclure_lignes}
|
||||
if statut is not None:
|
||||
|
|
@ -117,10 +112,24 @@ class SageGatewayClient:
|
|||
return self._post("/sage/devis/list", payload).get("data", [])
|
||||
|
||||
def changer_statut_devis(self, numero: str, nouveau_statut: int) -> Dict:
|
||||
"""✅ NOUVEAU: Change le statut d'un devis"""
|
||||
return self._post(
|
||||
"/sage/devis/statut", {"numero": numero, "nouveau_statut": nouveau_statut}
|
||||
).get("data", {})
|
||||
"""
|
||||
✅ CORRECTION: Utilise query params au lieu du body
|
||||
"""
|
||||
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
|
||||
|
|
@ -134,15 +143,25 @@ class SageGatewayClient:
|
|||
def transformer_document(
|
||||
self, numero_source: str, type_source: int, type_cible: int
|
||||
) -> Dict:
|
||||
"""Transformation de document (devis → commande → facture)"""
|
||||
return self._post(
|
||||
"/sage/documents/transform",
|
||||
{
|
||||
"numero_source": numero_source,
|
||||
"type_source": type_source,
|
||||
"type_cible": type_cible,
|
||||
},
|
||||
).get("data", {})
|
||||
"""
|
||||
✅ CORRECTION: Utilise query params pour la transformation
|
||||
"""
|
||||
try:
|
||||
r = requests.post(
|
||||
f"{self.url}/sage/documents/transform",
|
||||
params={ # ← QUERY PARAMS
|
||||
"numero_source": numero_source,
|
||||
"type_source": type_source,
|
||||
"type_cible": type_cible,
|
||||
},
|
||||
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(
|
||||
self, doc_id: str, type_doc: int, nom_champ: str, valeur: str
|
||||
|
|
@ -165,7 +184,7 @@ class SageGatewayClient:
|
|||
def lister_commandes(
|
||||
self, limit: int = 100, statut: Optional[int] = None
|
||||
) -> List[Dict]:
|
||||
"""✅ NOUVEAU: Liste toutes les commandes"""
|
||||
"""Liste toutes les commandes"""
|
||||
payload = {"limit": limit}
|
||||
if statut is not None:
|
||||
payload["statut"] = statut
|
||||
|
|
@ -177,14 +196,14 @@ class SageGatewayClient:
|
|||
def lister_factures(
|
||||
self, limit: int = 100, statut: Optional[int] = None
|
||||
) -> List[Dict]:
|
||||
"""✅ NOUVEAU: Liste toutes les factures"""
|
||||
"""Liste toutes les factures"""
|
||||
payload = {"limit": limit}
|
||||
if statut is not None:
|
||||
payload["statut"] = statut
|
||||
return self._post("/sage/factures/list", payload).get("data", [])
|
||||
|
||||
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(
|
||||
"/sage/documents/derniere-relance", {"doc_id": doc_id, "type_doc": type_doc}
|
||||
)
|
||||
|
|
@ -201,7 +220,7 @@ class SageGatewayClient:
|
|||
# REMISES (US-A5)
|
||||
# =====================================================
|
||||
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})
|
||||
return result.get("data", {}).get("remise_max", 10.0)
|
||||
|
||||
|
|
@ -209,17 +228,16 @@ class SageGatewayClient:
|
|||
# GÉNÉRATION PDF (pour email_queue)
|
||||
# =====================================================
|
||||
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:
|
||||
r = requests.post(
|
||||
f"{self.url}/sage/documents/generate-pdf",
|
||||
json={"doc_id": doc_id, "type_doc": type_doc},
|
||||
headers=self.headers,
|
||||
timeout=60, # Timeout plus long pour génération PDF
|
||||
timeout=60,
|
||||
)
|
||||
r.raise_for_status()
|
||||
|
||||
# Le PDF est retourné en base64 dans la réponse JSON
|
||||
import base64
|
||||
|
||||
response_data = r.json()
|
||||
|
|
|
|||
Loading…
Reference in a new issue