enriched client's details data

This commit is contained in:
fanilo 2025-12-26 14:41:38 +01:00
parent c9497adad2
commit 5591bff7b3
2 changed files with 168 additions and 24 deletions

17
cleaner.py Normal file
View file

@ -0,0 +1,17 @@
from pathlib import Path
def supprimer_commentaires_ligne(fichier: str) -> None:
path = Path(fichier)
lignes_filtrees = []
with path.open("r", encoding="utf-8") as f:
for ligne in f:
if ligne.lstrip().startswith("#"):
continue
lignes_filtrees.append(ligne)
path.write_text("".join(lignes_filtrees), encoding="utf-8")
if __name__ == "__main__":
supprimer_commentaires_ligne("api.py")

View file

@ -772,16 +772,64 @@ class SageConnector:
raise RuntimeError(f"Erreur technique Sage: {error_message}")
def lister_tous_clients(self, filtre=""):
"""
Liste tous les clients avec TOUS les champs gérés par creer_client
Symétrie complète GET/POST
"""
try:
with self._get_sql_connection() as conn:
cursor = conn.cursor()
query = """
SELECT
-- IDENTIFICATION (8)
CT_Num, CT_Intitule, CT_Type, CT_Qualite,
CT_Adresse, CT_Ville, CT_CodePostal, CT_Pays,
CT_Telephone, CT_EMail, CT_Siret, CT_Identifiant,
CT_Sommeil, CT_Prospect, CT_Contact
CT_Classement, CT_Raccourci, CT_Siret, CT_Identifiant,
CT_Ape,
-- ADRESSE (7)
CT_Contact, CT_Adresse, CT_Complement,
CT_CodePostal, CT_Ville, CT_CodeRegion, CT_Pays,
-- TELECOM (7)
CT_Telephone, CT_Telecopie, CT_EMail, CT_Site,
CT_Facebook, CT_LinkedIn,
-- TAUX (4)
CT_Taux01, CT_Taux02, CT_Taux03, CT_Taux04,
-- STATISTIQUES (10)
CT_Statistique01, CT_Statistique02, CT_Statistique03,
CT_Statistique04, CT_Statistique05, CT_Statistique06,
CT_Statistique07, CT_Statistique08, CT_Statistique09,
CT_Statistique10,
-- COMMERCIAL (4)
CT_Encours, CT_Assurance, CT_Langue, CO_No,
-- FACTURATION (11)
CT_Lettrage, CT_Sommeil, CT_Facture, CT_Prospect,
CT_BLFact, CT_Saut, CT_ValidEch, CT_ControlEnc,
CT_NotRappel, CT_NotPenal, CT_BonAPayer,
-- LOGISTIQUE (4)
CT_PrioriteLivr, CT_LivrPartielle,
CT_DelaiTransport, CT_DelaiAppro,
-- COMMENTAIRE (1)
CT_Commentaire,
-- ANALYTIQUE (1)
CA_Num,
-- ORGANISATION / SURVEILLANCE (10)
MR_No, CT_Surveillance, CT_Coface,
CT_SvFormeJuri, CT_SvEffectif, CT_SvRegul,
CT_SvCotation, CT_SvObjetMaj, CT_SvCA, CT_SvResultat,
-- COMPTE GENERAL ET CATEGORIES (3)
CG_NumPrinc, N_CatTarif, N_CatCompta
FROM F_COMPTET
WHERE CT_Type = 0
"""
@ -799,33 +847,112 @@ class SageConnector:
clients = []
for row in rows:
clients.append(
{
"numero": self._safe_strip(row.CT_Num),
"intitule": self._safe_strip(row.CT_Intitule),
"type": row.CT_Type,
"qualite": self._safe_strip(row.CT_Qualite),
"adresse": self._safe_strip(row.CT_Adresse),
"ville": self._safe_strip(row.CT_Ville),
"code_postal": self._safe_strip(row.CT_CodePostal),
"pays": self._safe_strip(row.CT_Pays),
"telephone": self._safe_strip(row.CT_Telephone),
"email": self._safe_strip(row.CT_EMail),
"siret": self._safe_strip(row.CT_Siret),
"tva_intra": self._safe_strip(row.CT_Identifiant),
"est_actif": (row.CT_Sommeil == 0),
"est_prospect": (row.CT_Prospect == 1),
"contact": self._safe_strip(row.CT_Contact),
}
)
client = {
# IDENTIFICATION
"numero": self._safe_strip(row.CT_Num),
"intitule": self._safe_strip(row.CT_Intitule),
"type_tiers": row.CT_Type,
"qualite": self._safe_strip(row.CT_Qualite),
"classement": self._safe_strip(row.CT_Classement),
"raccourci": self._safe_strip(row.CT_Raccourci),
"siret": self._safe_strip(row.CT_Siret),
"tva_intra": self._safe_strip(row.CT_Identifiant),
"code_naf": self._safe_strip(row.CT_Ape),
# ADRESSE
"contact": self._safe_strip(row.CT_Contact),
"adresse": self._safe_strip(row.CT_Adresse),
"complement": self._safe_strip(row.CT_Complement),
"code_postal": self._safe_strip(row.CT_CodePostal),
"ville": self._safe_strip(row.CT_Ville),
"region": self._safe_strip(row.CT_CodeRegion),
"pays": self._safe_strip(row.CT_Pays),
# TELECOM
"telephone": self._safe_strip(row.CT_Telephone),
"telecopie": self._safe_strip(row.CT_Telecopie),
"email": self._safe_strip(row.CT_EMail),
"site_web": self._safe_strip(row.CT_Site),
"facebook": self._safe_strip(row.CT_Facebook),
"linkedin": self._safe_strip(row.CT_LinkedIn),
# TAUX
"taux01": row.CT_Taux01,
"taux02": row.CT_Taux02,
"taux03": row.CT_Taux03,
"taux04": row.CT_Taux04,
# STATISTIQUES
"statistique01": self._safe_strip(row.CT_Statistique01),
"statistique02": self._safe_strip(row.CT_Statistique02),
"statistique03": self._safe_strip(row.CT_Statistique03),
"statistique04": self._safe_strip(row.CT_Statistique04),
"statistique05": self._safe_strip(row.CT_Statistique05),
"statistique06": self._safe_strip(row.CT_Statistique06),
"statistique07": self._safe_strip(row.CT_Statistique07),
"statistique08": self._safe_strip(row.CT_Statistique08),
"statistique09": self._safe_strip(row.CT_Statistique09),
"statistique10": self._safe_strip(row.CT_Statistique10),
# COMMERCIAL
"encours_autorise": row.CT_Encours,
"assurance_credit": row.CT_Assurance,
"langue": row.CT_Langue,
"commercial_code": row.CO_No,
# FACTURATION
"lettrage_auto": (row.CT_Lettrage == 1),
"est_actif": (row.CT_Sommeil == 0),
"type_facture": row.CT_Facture,
"est_prospect": (row.CT_Prospect == 1),
"bl_en_facture": row.CT_BLFact,
"saut_page": row.CT_Saut,
"validation_echeance": row.CT_ValidEch,
"controle_encours": row.CT_ControlEnc,
"exclure_relance": (row.CT_NotRappel == 1),
"exclure_penalites": (row.CT_NotPenal == 1),
"bon_a_payer": row.CT_BonAPayer,
# LOGISTIQUE
"priorite_livraison": row.CT_PrioriteLivr,
"livraison_partielle": row.CT_LivrPartielle,
"delai_transport": row.CT_DelaiTransport,
"delai_appro": row.CT_DelaiAppro,
# COMMENTAIRE
"commentaire": self._safe_strip(row.CT_Commentaire),
# ANALYTIQUE
"section_analytique": self._safe_strip(row.CA_Num),
# ORGANISATION / SURVEILLANCE
"mode_reglement_code": row.MR_No,
"surveillance_active": (row.CT_Surveillance == 1),
"coface": self._safe_strip(row.CT_Coface),
"forme_juridique": self._safe_strip(row.CT_SvFormeJuri),
"effectif": self._safe_strip(row.CT_SvEffectif),
"sv_regularite": self._safe_strip(row.CT_SvRegul),
"sv_cotation": self._safe_strip(row.CT_SvCotation),
"sv_objet_maj": self._safe_strip(row.CT_SvObjetMaj),
"sv_chiffre_affaires": row.CT_SvCA,
"sv_resultat": row.CT_SvResultat,
# COMPTE GENERAL ET CATEGORIES
"compte_general": self._safe_strip(row.CG_NumPrinc),
"categorie_tarif": row.N_CatTarif,
"categorie_compta": row.N_CatCompta,
}
clients.append(client)
logger.info(f" SQL: {len(clients)} clients")
logger.info(f" SQL: {len(clients)} clients avec {len(client)} champs")
return clients
except Exception as e:
logger.error(f" Erreur SQL clients: {e}")
logger.error(f" Erreur SQL clients: {e}")
raise RuntimeError(f"Erreur lecture clients: {str(e)}")
def lire_client(self, code_client):
try:
with self._get_sql_connection() as conn: