Added create client logics
This commit is contained in:
parent
77dcb21e4a
commit
2f9b2fc1a9
2 changed files with 45 additions and 1 deletions
38
api.py
38
api.py
|
|
@ -148,7 +148,19 @@ class BaremeRemiseResponse(BaseModel):
|
||||||
message: str
|
message: str
|
||||||
|
|
||||||
|
|
||||||
# À ajouter dans api.py après les imports et avant les endpoints existants
|
class ClientCreateAPIRequest(BaseModel):
|
||||||
|
intitule: str = Field(..., min_length=1, description="Raison sociale ou Nom")
|
||||||
|
compte_collectif: str = Field("411000", description="Compte Comptable (ex: 411000)")
|
||||||
|
num: Optional[str] = Field(None, description="Code client souhaité (optionnel)")
|
||||||
|
adresse: Optional[str] = None
|
||||||
|
code_postal: Optional[str] = None
|
||||||
|
ville: Optional[str] = None
|
||||||
|
pays: Optional[str] = None
|
||||||
|
email: Optional[EmailStr] = None
|
||||||
|
telephone: Optional[str] = None
|
||||||
|
siret: Optional[str] = None
|
||||||
|
tva_intra: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
@ -356,6 +368,30 @@ async def rechercher_clients(query: Optional[str] = Query(None)):
|
||||||
logger.error(f"Erreur recherche clients: {e}")
|
logger.error(f"Erreur recherche clients: {e}")
|
||||||
raise HTTPException(500, str(e))
|
raise HTTPException(500, str(e))
|
||||||
|
|
||||||
|
@app.post("/clients", status_code=201, tags=["US-A8"])
|
||||||
|
async def ajouter_client(
|
||||||
|
client: ClientCreateAPIRequest,
|
||||||
|
session: AsyncSession = Depends(get_session)
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
➕ Création d'un nouveau client dans Sage 100c
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
nouveau_client = sage_client.creer_client(client.dict())
|
||||||
|
|
||||||
|
logger.info(f"✅ Client créé via API: {nouveau_client.get('numero')}")
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"message": "Client créé avec succès",
|
||||||
|
"client": nouveau_client
|
||||||
|
}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Erreur lors de la création du client: {e}")
|
||||||
|
# On renvoie une 400 si c'est une erreur métier (ex: doublon), sinon 500
|
||||||
|
status = 400 if "existe déjà" in str(e) else 500
|
||||||
|
raise HTTPException(status, str(e))
|
||||||
|
|
||||||
@app.get("/articles", response_model=List[ArticleResponse], tags=["US-A1"])
|
@app.get("/articles", response_model=List[ArticleResponse], tags=["US-A1"])
|
||||||
async def rechercher_articles(query: Optional[str] = Query(None)):
|
async def rechercher_articles(query: Optional[str] = Query(None)):
|
||||||
|
|
|
||||||
|
|
@ -332,6 +332,14 @@ class SageGatewayClient:
|
||||||
except:
|
except:
|
||||||
return {"status": "down"}
|
return {"status": "down"}
|
||||||
|
|
||||||
|
def creer_client(self, client_data: Dict) -> Dict:
|
||||||
|
"""
|
||||||
|
Envoie la requête de création de client à la gateway Windows.
|
||||||
|
:param client_data: Dict contenant intitule, compte_collectif, etc.
|
||||||
|
"""
|
||||||
|
# On appelle la route définie dans main.py
|
||||||
|
return self._post("/sage/clients/create", client_data).get("data", {})
|
||||||
|
|
||||||
|
|
||||||
# Instance globale
|
# Instance globale
|
||||||
sage_client = SageGatewayClient()
|
sage_client = SageGatewayClient()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue