Reviewed and refactored files' structures and indentation
This commit is contained in:
parent
3bb1aee4b4
commit
0788f46bde
29 changed files with 1417 additions and 6237 deletions
|
|
@ -15,26 +15,21 @@ class Settings(BaseSettings):
|
||||||
SAGE_TYPE_BON_AVOIR: int = 50
|
SAGE_TYPE_BON_AVOIR: int = 50
|
||||||
SAGE_TYPE_FACTURE: int = 60
|
SAGE_TYPE_FACTURE: int = 60
|
||||||
|
|
||||||
# === SAGE 100c (Windows uniquement) ===
|
|
||||||
chemin_base: str
|
chemin_base: str
|
||||||
utilisateur: str = "Administrateur"
|
utilisateur: str = "Administrateur"
|
||||||
mot_de_passe: str
|
mot_de_passe: str
|
||||||
|
|
||||||
# === Sécurité Gateway ===
|
sage_gateway_token: str
|
||||||
sage_gateway_token: str # Token partagé avec le VPS Linux
|
|
||||||
|
|
||||||
# === SMTP (optionnel sur Windows) ===
|
|
||||||
smtp_host: Optional[str] = None
|
smtp_host: Optional[str] = None
|
||||||
smtp_port: int = 587
|
smtp_port: int = 587
|
||||||
smtp_user: Optional[str] = None
|
smtp_user: Optional[str] = None
|
||||||
smtp_password: Optional[str] = None
|
smtp_password: Optional[str] = None
|
||||||
smtp_from: Optional[str] = None
|
smtp_from: Optional[str] = None
|
||||||
|
|
||||||
# === API Windows ===
|
|
||||||
api_host: str = "0.0.0.0"
|
api_host: str = "0.0.0.0"
|
||||||
api_port: int = 8000
|
api_port: int = 8000
|
||||||
|
|
||||||
# === CORS ===
|
|
||||||
cors_origins: List[str] = ["*"]
|
cors_origins: List[str] = ["*"]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
======================================================================
|
|
||||||
DIAGNOSTIC CRYSTAL REPORTS
|
|
||||||
======================================================================
|
|
||||||
|
|
||||||
Installation détectée: True
|
|
||||||
DLL trouvées:
|
|
||||||
ProgID valides:
|
|
||||||
Architecture OK: False
|
|
||||||
|
|
||||||
PROBLÈMES:
|
|
||||||
|
|
||||||
SOLUTIONS:
|
|
||||||
47
main.py
47
main.py
|
|
@ -48,7 +48,7 @@ from schemas import (
|
||||||
SortieStockRequest,
|
SortieStockRequest,
|
||||||
FamilleCreate,
|
FamilleCreate,
|
||||||
PDFGenerationRequest,
|
PDFGenerationRequest,
|
||||||
DevisUpdateGatewayRequest
|
DevisUpdateGatewayRequest,
|
||||||
)
|
)
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
|
|
@ -58,6 +58,7 @@ logging.basicConfig(
|
||||||
)
|
)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def verify_token(x_sage_token: str = Header(...)):
|
def verify_token(x_sage_token: str = Header(...)):
|
||||||
"""Vérification du token d'authentification"""
|
"""Vérification du token d'authentification"""
|
||||||
if x_sage_token != settings.sage_gateway_token:
|
if x_sage_token != settings.sage_gateway_token:
|
||||||
|
|
@ -278,7 +279,9 @@ def changer_statut_document(numero: str, type_doc: int, nouveau_statut: int):
|
||||||
doc.DO_Statut = nouveau_statut
|
doc.DO_Statut = nouveau_statut
|
||||||
doc.Write()
|
doc.Write()
|
||||||
|
|
||||||
logger.info(f" Statut document {numero}: {statut_actuel} → {nouveau_statut}")
|
logger.info(
|
||||||
|
f" Statut document {numero}: {statut_actuel} → {nouveau_statut}"
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
|
|
@ -323,11 +326,11 @@ def transformer_document(
|
||||||
)
|
)
|
||||||
|
|
||||||
transformations_valides = {
|
transformations_valides = {
|
||||||
(0, 10), # Devis → Commande
|
(0, 10),
|
||||||
(10, 30), # Commande → Bon de livraison
|
(10, 30),
|
||||||
(10, 60), # Commande → Facture
|
(10, 60),
|
||||||
(30, 60), # Bon de livraison → Facture
|
(30, 60),
|
||||||
(0, 60), # Devis → Facture (si autorisé)
|
(0, 60),
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type_source, type_cible) not in transformations_valides:
|
if (type_source, type_cible) not in transformations_valides:
|
||||||
|
|
@ -443,11 +446,11 @@ def lire_remise_max_client(code: str):
|
||||||
if not client_obj:
|
if not client_obj:
|
||||||
raise HTTPException(404, f"Client {code} introuvable")
|
raise HTTPException(404, f"Client {code} introuvable")
|
||||||
|
|
||||||
remise_max = 10.0 # Défaut
|
remise_max = 10.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
remise_max = float(getattr(client_obj, "CT_RemiseMax", 10.0))
|
remise_max = float(getattr(client_obj, "CT_RemiseMax", 10.0))
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
logger.info(f" Remise max client {code}: {remise_max}%")
|
logger.info(f" Remise max client {code}: {remise_max}%")
|
||||||
|
|
@ -633,7 +636,7 @@ def livraisons_list(
|
||||||
livraisons = sage.lister_toutes_livraisons_cache(filtre)
|
livraisons = sage.lister_toutes_livraisons_cache(filtre)
|
||||||
|
|
||||||
if statut is not None:
|
if statut is not None:
|
||||||
livraisons = [l for l in livraisons if l.get("statut") == statut]
|
livraisons = [ligne for ligne in livraisons if ligne.get("statut") == statut]
|
||||||
|
|
||||||
livraisons = livraisons[:limit]
|
livraisons = livraisons[:limit]
|
||||||
|
|
||||||
|
|
@ -1026,7 +1029,7 @@ def lister_depots():
|
||||||
factory_depot = sage.cial.FactoryDepot
|
factory_depot = sage.cial.FactoryDepot
|
||||||
|
|
||||||
index = 1
|
index = 1
|
||||||
while index <= 100: # Max 100 dépôts
|
while index <= 100:
|
||||||
try:
|
try:
|
||||||
persist = factory_depot.List(index)
|
persist = factory_depot.List(index)
|
||||||
|
|
||||||
|
|
@ -1045,30 +1048,30 @@ def lister_depots():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
code = getattr(depot, "DE_Code", "").strip()
|
code = getattr(depot, "DE_Code", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
numero = int(getattr(depot, "Compteur", 0))
|
numero = int(getattr(depot, "Compteur", 0))
|
||||||
except:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
numero = int(code)
|
numero = int(code)
|
||||||
except:
|
except Exception:
|
||||||
numero = 0
|
numero = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
intitule = getattr(depot, "DE_Intitule", "")
|
intitule = getattr(depot, "DE_Intitule", "")
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
contact = getattr(depot, "DE_Contact", "")
|
contact = getattr(depot, "DE_Contact", "")
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
exclu = getattr(depot, "DE_Exclure", False)
|
exclu = getattr(depot, "DE_Exclure", False)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not code:
|
if not code:
|
||||||
|
|
@ -1085,9 +1088,9 @@ def lister_depots():
|
||||||
cp = getattr(adresse_obj, "CodePostal", "")
|
cp = getattr(adresse_obj, "CodePostal", "")
|
||||||
ville = getattr(adresse_obj, "Ville", "")
|
ville = getattr(adresse_obj, "Ville", "")
|
||||||
adresse_complete = f"{adresse} {cp} {ville}".strip()
|
adresse_complete = f"{adresse} {cp} {ville}".strip()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
principal = False
|
principal = False
|
||||||
|
|
@ -1095,8 +1098,8 @@ def lister_depots():
|
||||||
principal = True
|
principal = True
|
||||||
|
|
||||||
depot_info = {
|
depot_info = {
|
||||||
"code": code, # ⭐ "01", "02"
|
"code": code,
|
||||||
"numero": numero, # ⭐ 1, 2 (depuis Compteur)
|
"numero": numero,
|
||||||
"intitule": intitule,
|
"intitule": intitule,
|
||||||
"adresse": adresse_complete,
|
"adresse": adresse_complete,
|
||||||
"contact": contact,
|
"contact": contact,
|
||||||
|
|
@ -1341,6 +1344,6 @@ if __name__ == "__main__":
|
||||||
"main:app",
|
"main:app",
|
||||||
host=settings.api_host,
|
host=settings.api_host,
|
||||||
port=settings.api_port,
|
port=settings.api_port,
|
||||||
reload=False, # Pas de reload en production
|
reload=False,
|
||||||
log_level="info",
|
log_level="info",
|
||||||
)
|
)
|
||||||
|
|
|
||||||
4514
main.py.bak
4514
main.py.bak
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,9 +1,7 @@
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, validator, EmailStr, field_validator
|
|
||||||
from typing import Optional, List, Dict
|
from typing import Optional, List, Dict
|
||||||
from enum import Enum, IntEnum
|
from datetime import date
|
||||||
from datetime import datetime, date
|
|
||||||
|
|
||||||
class AvoirCreateGatewayRequest(BaseModel):
|
class AvoirCreateGatewayRequest(BaseModel):
|
||||||
"""Création d'un avoir côté gateway"""
|
"""Création d'un avoir côté gateway"""
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
|
from pydantic import BaseModel
|
||||||
from pydantic import BaseModel, Field, validator, EmailStr, field_validator
|
|
||||||
from typing import Optional, List, Dict
|
from typing import Optional, List, Dict
|
||||||
from enum import Enum, IntEnum
|
from datetime import date
|
||||||
from datetime import datetime, date
|
|
||||||
|
|
||||||
class CommandeCreateRequest(BaseModel):
|
class CommandeCreateRequest(BaseModel):
|
||||||
"""Création d'une commande"""
|
"""Création d'une commande"""
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, validator, EmailStr, field_validator
|
|
||||||
from typing import Optional, List, Dict
|
from typing import Optional, List, Dict
|
||||||
from enum import Enum, IntEnum
|
from datetime import date
|
||||||
from datetime import datetime, date
|
|
||||||
|
|
||||||
class DevisRequest(BaseModel):
|
class DevisRequest(BaseModel):
|
||||||
client_id: str
|
client_id: str
|
||||||
|
|
@ -12,6 +10,7 @@ class DevisRequest(BaseModel):
|
||||||
reference: Optional[str] = None
|
reference: Optional[str] = None
|
||||||
lignes: List[Dict]
|
lignes: List[Dict]
|
||||||
|
|
||||||
|
|
||||||
class DevisUpdateGatewayRequest(BaseModel):
|
class DevisUpdateGatewayRequest(BaseModel):
|
||||||
"""Modèle pour modification devis côté gateway"""
|
"""Modèle pour modification devis côté gateway"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, validator, EmailStr, field_validator
|
|
||||||
from typing import Optional, List, Dict
|
|
||||||
from enum import Enum, IntEnum
|
|
||||||
from datetime import datetime, date
|
|
||||||
|
|
||||||
class TypeDocument(int, Enum):
|
class TypeDocument(int, Enum):
|
||||||
DEVIS = 0
|
DEVIS = 0
|
||||||
|
|
@ -17,16 +15,15 @@ class DocumentGetRequest(BaseModel):
|
||||||
numero: str
|
numero: str
|
||||||
type_doc: int
|
type_doc: int
|
||||||
|
|
||||||
|
|
||||||
class TransformationRequest(BaseModel):
|
class TransformationRequest(BaseModel):
|
||||||
numero_source: str
|
numero_source: str
|
||||||
type_source: int
|
type_source: int
|
||||||
type_cible: int
|
type_cible: int
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PDFGenerationRequest(BaseModel):
|
class PDFGenerationRequest(BaseModel):
|
||||||
"""Modèle pour génération PDF"""
|
"""Modèle pour génération PDF"""
|
||||||
|
|
||||||
doc_id: str = Field(..., description="Numéro du document")
|
doc_id: str = Field(..., description="Numéro du document")
|
||||||
type_doc: int = Field(..., ge=0, le=60, description="Type de document Sage")
|
type_doc: int = Field(..., ge=0, le=60, description="Type de document Sage")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, validator, EmailStr, field_validator
|
|
||||||
from typing import Optional, List, Dict
|
from typing import Optional, List, Dict
|
||||||
from enum import Enum, IntEnum
|
from datetime import date
|
||||||
from datetime import datetime, date
|
|
||||||
|
|
||||||
class FactureCreateGatewayRequest(BaseModel):
|
class FactureCreateGatewayRequest(BaseModel):
|
||||||
"""Création d'une facture côté gateway"""
|
"""Création d'une facture côté gateway"""
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
|
from pydantic import BaseModel
|
||||||
from pydantic import BaseModel, Field, validator, EmailStr, field_validator
|
|
||||||
from typing import Optional, List, Dict
|
from typing import Optional, List, Dict
|
||||||
from enum import Enum, IntEnum
|
from datetime import date
|
||||||
from datetime import datetime, date
|
|
||||||
|
|
||||||
class LivraisonCreateGatewayRequest(BaseModel):
|
class LivraisonCreateGatewayRequest(BaseModel):
|
||||||
"""Création d'une livraison côté gateway"""
|
"""Création d'une livraison côté gateway"""
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, validator, EmailStr, field_validator
|
|
||||||
from typing import Optional, List, Dict
|
|
||||||
|
|
||||||
class FiltreRequest(BaseModel):
|
class FiltreRequest(BaseModel):
|
||||||
filtre: Optional[str] = ""
|
filtre: Optional[str] = ""
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from pydantic import BaseModel, Field, validator, EmailStr, field_validator
|
from pydantic import BaseModel, Field, field_validator
|
||||||
from typing import Optional, List, Dict
|
from typing import Optional, Dict
|
||||||
|
|
||||||
|
|
||||||
class ClientCreateRequest(BaseModel):
|
class ClientCreateRequest(BaseModel):
|
||||||
intitule: str = Field(
|
intitule: str = Field(
|
||||||
|
|
@ -348,7 +349,7 @@ class ClientCreateRequest(BaseModel):
|
||||||
"statistique08": self.statistique08,
|
"statistique08": self.statistique08,
|
||||||
"statistique09": self.statistique09,
|
"statistique09": self.statistique09,
|
||||||
"statistique10": self.statistique10,
|
"statistique10": self.statistique10,
|
||||||
"secteur": self.secteur, # Gardé pour compatibilité
|
"secteur": self.secteur,
|
||||||
"encours_autorise": self.encours_autorise,
|
"encours_autorise": self.encours_autorise,
|
||||||
"assurance_credit": self.assurance_credit,
|
"assurance_credit": self.assurance_credit,
|
||||||
"langue": self.langue,
|
"langue": self.langue,
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import Optional, Dict
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, validator, EmailStr, field_validator
|
|
||||||
from typing import Optional, List, Dict
|
|
||||||
|
|
||||||
class ContactCreateRequest(BaseModel):
|
class ContactCreateRequest(BaseModel):
|
||||||
"""Requête de création de contact"""
|
"""Requête de création de contact"""
|
||||||
|
|
||||||
numero: str
|
numero: str
|
||||||
civilite: Optional[str] = None
|
civilite: Optional[str] = None
|
||||||
nom: str
|
nom: str
|
||||||
|
|
@ -21,17 +22,20 @@ class ContactCreateRequest(BaseModel):
|
||||||
|
|
||||||
class ContactListRequest(BaseModel):
|
class ContactListRequest(BaseModel):
|
||||||
"""Requête de liste des contacts"""
|
"""Requête de liste des contacts"""
|
||||||
|
|
||||||
numero: str
|
numero: str
|
||||||
|
|
||||||
|
|
||||||
class ContactGetRequest(BaseModel):
|
class ContactGetRequest(BaseModel):
|
||||||
"""Requête de récupération d'un contact"""
|
"""Requête de récupération d'un contact"""
|
||||||
|
|
||||||
numero: str
|
numero: str
|
||||||
contact_numero: int
|
contact_numero: int
|
||||||
|
|
||||||
|
|
||||||
class ContactUpdateRequest(BaseModel):
|
class ContactUpdateRequest(BaseModel):
|
||||||
"""Requête de modification d'un contact"""
|
"""Requête de modification d'un contact"""
|
||||||
|
|
||||||
numero: str
|
numero: str
|
||||||
contact_numero: int
|
contact_numero: int
|
||||||
updates: Dict
|
updates: Dict
|
||||||
|
|
@ -39,5 +43,6 @@ class ContactUpdateRequest(BaseModel):
|
||||||
|
|
||||||
class ContactDeleteRequest(BaseModel):
|
class ContactDeleteRequest(BaseModel):
|
||||||
"""Requête de suppression d'un contact"""
|
"""Requête de suppression d'un contact"""
|
||||||
|
|
||||||
numero: str
|
numero: str
|
||||||
contact_numero: int
|
contact_numero: int
|
||||||
|
|
@ -1,21 +1,5 @@
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
from pydantic import BaseModel, Field, validator, EmailStr, field_validator
|
from typing import Optional, Dict
|
||||||
from typing import Optional, List, Dict
|
|
||||||
from enum import Enum, IntEnum
|
|
||||||
from datetime import datetime, date
|
|
||||||
|
|
||||||
class FournisseurCreateRequest(BaseModel):
|
|
||||||
intitule: str = Field(..., description="Raison sociale du fournisseur")
|
|
||||||
compte_collectif: str = Field("401000", description="Compte général rattaché")
|
|
||||||
num: Optional[str] = Field(None, description="Code fournisseur (auto si vide)")
|
|
||||||
adresse: Optional[str] = None
|
|
||||||
code_postal: Optional[str] = None
|
|
||||||
ville: Optional[str] = None
|
|
||||||
pays: Optional[str] = None
|
|
||||||
email: Optional[str] = None
|
|
||||||
telephone: Optional[str] = None
|
|
||||||
siret: Optional[str] = None
|
|
||||||
tva_intra: Optional[str] = None
|
|
||||||
|
|
||||||
|
|
||||||
class FournisseurCreateRequest(BaseModel):
|
class FournisseurCreateRequest(BaseModel):
|
||||||
|
|
@ -37,5 +21,3 @@ class FournisseurUpdateGatewayRequest(BaseModel):
|
||||||
|
|
||||||
code: str
|
code: str
|
||||||
fournisseur_data: Dict
|
fournisseur_data: Dict
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,16 @@
|
||||||
from pydantic import BaseModel, Field, validator, EmailStr, field_validator
|
from pydantic import BaseModel, Field
|
||||||
from typing import Optional, List, Dict
|
from typing import Optional
|
||||||
from enum import Enum, IntEnum
|
from enum import IntEnum
|
||||||
|
|
||||||
|
|
||||||
class TiersListRequest(BaseModel):
|
class TiersListRequest(BaseModel):
|
||||||
"""Requête de listage des tiers"""
|
"""Requête de listage des tiers"""
|
||||||
|
|
||||||
type_tiers: Optional[str] = Field(
|
type_tiers: Optional[str] = Field(
|
||||||
None,
|
None, description="Type: client, fournisseur, prospect, all"
|
||||||
description="Type: client, fournisseur, prospect, all"
|
|
||||||
)
|
|
||||||
filtre: str = Field(
|
|
||||||
"",
|
|
||||||
description="Filtre sur code ou intitulé"
|
|
||||||
)
|
)
|
||||||
|
filtre: str = Field("", description="Filtre sur code ou intitulé")
|
||||||
|
|
||||||
|
|
||||||
class TypeTiers(IntEnum):
|
class TypeTiers(IntEnum):
|
||||||
"""CT_Type - Type de tiers"""
|
"""CT_Type - Type de tiers"""
|
||||||
|
|
|
||||||
323
test.py
323
test.py
|
|
@ -1,323 +0,0 @@
|
||||||
"""
|
|
||||||
🔬 DIAGNOSTIC APPROFONDI CRYSTAL REPORTS
|
|
||||||
Découvre pourquoi Crystal ne fonctionne pas après redémarrage
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import winreg
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
|
|
||||||
def diagnostic_complet_crystal():
|
|
||||||
"""Diagnostic exhaustif de l'installation Crystal"""
|
|
||||||
|
|
||||||
print("="*70)
|
|
||||||
print("🔬 DIAGNOSTIC APPROFONDI CRYSTAL REPORTS")
|
|
||||||
print("="*70)
|
|
||||||
|
|
||||||
problemes = []
|
|
||||||
solutions = []
|
|
||||||
|
|
||||||
# ==========================================
|
|
||||||
# 1. VÉRIFIER SI CRYSTAL EST INSTALLÉ
|
|
||||||
# ==========================================
|
|
||||||
print("\n📁 1. Vérification présence des fichiers...")
|
|
||||||
|
|
||||||
chemins_installation = [
|
|
||||||
r"C:\Program Files\SAP BusinessObjects",
|
|
||||||
r"C:\Program Files (x86)\SAP BusinessObjects",
|
|
||||||
r"C:\Program Files\SAP\Crystal Reports",
|
|
||||||
r"C:\Program Files (x86)\SAP\Crystal Reports",
|
|
||||||
]
|
|
||||||
|
|
||||||
crystal_trouve = False
|
|
||||||
chemin_crystal = None
|
|
||||||
|
|
||||||
for chemin in chemins_installation:
|
|
||||||
if os.path.exists(chemin):
|
|
||||||
print(f" Dossier trouvé : {chemin}")
|
|
||||||
crystal_trouve = True
|
|
||||||
chemin_crystal = chemin
|
|
||||||
|
|
||||||
# Afficher taille
|
|
||||||
try:
|
|
||||||
total_size = 0
|
|
||||||
for dirpath, dirnames, filenames in os.walk(chemin):
|
|
||||||
for f in filenames:
|
|
||||||
fp = os.path.join(dirpath, f)
|
|
||||||
try:
|
|
||||||
total_size += os.path.getsize(fp)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
size_mb = total_size / (1024 * 1024)
|
|
||||||
print(f" Taille : {size_mb:.1f} MB")
|
|
||||||
|
|
||||||
if size_mb < 100:
|
|
||||||
print(f" Taille suspecte (attendu: 300-800 MB)")
|
|
||||||
problemes.append("Installation incomplète (taille trop petite)")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f" Impossible de calculer taille : {e}")
|
|
||||||
else:
|
|
||||||
print(f" Absent : {chemin}")
|
|
||||||
|
|
||||||
if not crystal_trouve:
|
|
||||||
print("\n PROBLÈME MAJEUR : Crystal Reports n'est pas installé")
|
|
||||||
problemes.append("Crystal Reports non installé")
|
|
||||||
solutions.append("Télécharger et installer SAP Crystal Reports Runtime")
|
|
||||||
return {"problemes": problemes, "solutions": solutions, "installe": False}
|
|
||||||
|
|
||||||
# ==========================================
|
|
||||||
# 2. CHERCHER LES DLL CRITIQUES
|
|
||||||
# ==========================================
|
|
||||||
print("\n📦 2. Recherche DLL critiques...")
|
|
||||||
|
|
||||||
dll_critiques = {
|
|
||||||
'crpe32.dll': 'Crystal Reports Print Engine (CRITIQUE)',
|
|
||||||
'crxf_pdf.dll': 'Export PDF (CRITIQUE)',
|
|
||||||
'crdb_adoplus.dll': 'Connexion base de données',
|
|
||||||
'CrystalDecisions.CrystalReports.Engine.dll': 'Moteur Crystal .NET',
|
|
||||||
}
|
|
||||||
|
|
||||||
dll_trouvees = {}
|
|
||||||
|
|
||||||
for dll_nom, description in dll_critiques.items():
|
|
||||||
trouve = False
|
|
||||||
|
|
||||||
for root, dirs, files in os.walk(chemin_crystal):
|
|
||||||
if dll_nom.lower() in [f.lower() for f in files]:
|
|
||||||
dll_path = os.path.join(root, dll_nom)
|
|
||||||
dll_trouvees[dll_nom] = dll_path
|
|
||||||
print(f" {dll_nom}")
|
|
||||||
print(f" {dll_path}")
|
|
||||||
trouve = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if not trouve:
|
|
||||||
print(f" {dll_nom} - {description}")
|
|
||||||
if "CRITIQUE" in description:
|
|
||||||
problemes.append(f"{dll_nom} manquante")
|
|
||||||
|
|
||||||
if len(dll_trouvees) < 2:
|
|
||||||
print("\n Trop peu de DLL trouvées - Installation corrompue")
|
|
||||||
problemes.append("DLL manquantes - Installation corrompue")
|
|
||||||
solutions.append("Réinstaller Crystal Reports Runtime")
|
|
||||||
|
|
||||||
# ==========================================
|
|
||||||
# 3. VÉRIFIER LE REGISTRE
|
|
||||||
# ==========================================
|
|
||||||
print("\n📋 3. Vérification registre Windows...")
|
|
||||||
|
|
||||||
prog_ids = [
|
|
||||||
"CrystalRuntime.Application.140",
|
|
||||||
"CrystalRuntime.Application.13",
|
|
||||||
"CrystalRuntime.Application.12",
|
|
||||||
"CrystalRuntime.Application",
|
|
||||||
"CrystalDesignRunTime.Application",
|
|
||||||
]
|
|
||||||
|
|
||||||
prog_ids_trouves = []
|
|
||||||
|
|
||||||
for prog_id in prog_ids:
|
|
||||||
try:
|
|
||||||
# Vérifier existence
|
|
||||||
key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, prog_id)
|
|
||||||
print(f" {prog_id}")
|
|
||||||
|
|
||||||
# Lire le CLSID
|
|
||||||
try:
|
|
||||||
clsid_key = winreg.OpenKey(key, "CLSID")
|
|
||||||
clsid, _ = winreg.QueryValueEx(clsid_key, "")
|
|
||||||
print(f" CLSID: {clsid}")
|
|
||||||
|
|
||||||
# Vérifier que le CLSID existe aussi
|
|
||||||
try:
|
|
||||||
clsid_path = f"CLSID\\{clsid}"
|
|
||||||
clsid_key_check = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, clsid_path)
|
|
||||||
|
|
||||||
# Lire InprocServer32 (chemin DLL)
|
|
||||||
try:
|
|
||||||
server_key = winreg.OpenKey(clsid_key_check, "InprocServer32")
|
|
||||||
dll_path, _ = winreg.QueryValueEx(server_key, "")
|
|
||||||
print(f" DLL: {dll_path}")
|
|
||||||
|
|
||||||
# Vérifier que la DLL existe
|
|
||||||
if not os.path.exists(dll_path):
|
|
||||||
print(f" DLL INTROUVABLE: {dll_path}")
|
|
||||||
problemes.append(f"{prog_id}: DLL manquante ({dll_path})")
|
|
||||||
else:
|
|
||||||
prog_ids_trouves.append(prog_id)
|
|
||||||
|
|
||||||
except:
|
|
||||||
print(f" InprocServer32 non trouvé")
|
|
||||||
|
|
||||||
except:
|
|
||||||
print(f" CLSID {clsid} non trouvé dans registre")
|
|
||||||
problemes.append(f"{prog_id}: CLSID cassé")
|
|
||||||
|
|
||||||
except:
|
|
||||||
print(f" Pas de CLSID")
|
|
||||||
|
|
||||||
winreg.CloseKey(key)
|
|
||||||
|
|
||||||
except:
|
|
||||||
print(f" {prog_id}")
|
|
||||||
|
|
||||||
if not prog_ids_trouves:
|
|
||||||
print("\n Aucun ProgID valide - Enregistrement COM échoué")
|
|
||||||
problemes.append("ProgID non enregistrés correctement")
|
|
||||||
solutions.append("Réenregistrer les DLL Crystal avec regsvr32")
|
|
||||||
|
|
||||||
# ==========================================
|
|
||||||
# 4. VÉRIFIER ARCHITECTURE (32 vs 64 bit)
|
|
||||||
# ==========================================
|
|
||||||
print("\n🔧 4. Vérification architecture...")
|
|
||||||
|
|
||||||
# Architecture Python
|
|
||||||
python_arch = "64-bit" if sys.maxsize > 2**32 else "32-bit"
|
|
||||||
print(f" Python : {python_arch}")
|
|
||||||
|
|
||||||
# Architecture système
|
|
||||||
import platform
|
|
||||||
sys_arch = platform.machine()
|
|
||||||
print(f" Système : {sys_arch}")
|
|
||||||
|
|
||||||
# Détecter architecture Crystal installée
|
|
||||||
crystal_arch = None
|
|
||||||
if dll_trouvees:
|
|
||||||
first_dll = list(dll_trouvees.values())[0]
|
|
||||||
if "win64_x64" in first_dll or "x64" in first_dll:
|
|
||||||
crystal_arch = "64-bit"
|
|
||||||
elif "win32_x86" in first_dll or "x86" in first_dll:
|
|
||||||
crystal_arch = "32-bit"
|
|
||||||
|
|
||||||
if crystal_arch:
|
|
||||||
print(f" Crystal : {crystal_arch}")
|
|
||||||
|
|
||||||
if python_arch != crystal_arch:
|
|
||||||
print(f"\n INCOMPATIBILITÉ ARCHITECTURE")
|
|
||||||
print(f" Python {python_arch} ne peut pas utiliser Crystal {crystal_arch}")
|
|
||||||
problemes.append(f"Incompatibilité: Python {python_arch} vs Crystal {crystal_arch}")
|
|
||||||
solutions.append(f"Réinstaller Crystal en version {python_arch}")
|
|
||||||
|
|
||||||
# ==========================================
|
|
||||||
# 5. VÉRIFIER SERVICES WINDOWS
|
|
||||||
# ==========================================
|
|
||||||
print("\n🔄 5. Vérification services Windows...")
|
|
||||||
|
|
||||||
try:
|
|
||||||
result = subprocess.run(
|
|
||||||
['sc', 'query', 'type=', 'service'],
|
|
||||||
capture_output=True,
|
|
||||||
text=True,
|
|
||||||
timeout=10
|
|
||||||
)
|
|
||||||
|
|
||||||
services_crystal_attendus = [
|
|
||||||
"SAP Crystal Reports",
|
|
||||||
"Crystal Reports",
|
|
||||||
"CrystalReports",
|
|
||||||
]
|
|
||||||
|
|
||||||
services_trouves = []
|
|
||||||
for service in services_crystal_attendus:
|
|
||||||
if service.lower() in result.stdout.lower():
|
|
||||||
services_trouves.append(service)
|
|
||||||
print(f" Service trouvé: {service}")
|
|
||||||
|
|
||||||
if not services_trouves:
|
|
||||||
print(f" Aucun service Crystal trouvé")
|
|
||||||
print(f" (Normal pour Runtime léger)")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f" Impossible de vérifier services: {e}")
|
|
||||||
|
|
||||||
# ==========================================
|
|
||||||
# 6. TEST INSTANCIATION COM DÉTAILLÉ
|
|
||||||
# ==========================================
|
|
||||||
print("\n🧪 6. Test instanciation COM détaillé...")
|
|
||||||
|
|
||||||
import win32com.client
|
|
||||||
|
|
||||||
for prog_id in prog_ids_trouves:
|
|
||||||
print(f"\n Test: {prog_id}")
|
|
||||||
try:
|
|
||||||
obj = win32com.client.Dispatch(prog_id)
|
|
||||||
print(f" Instanciation RÉUSSIE")
|
|
||||||
|
|
||||||
# Lister méthodes disponibles
|
|
||||||
print(f" Méthodes disponibles:")
|
|
||||||
for attr in dir(obj):
|
|
||||||
if not attr.startswith('_') and callable(getattr(obj, attr, None)):
|
|
||||||
print(f" - {attr}()")
|
|
||||||
|
|
||||||
return {
|
|
||||||
"problemes": problemes,
|
|
||||||
"solutions": solutions,
|
|
||||||
"installe": True,
|
|
||||||
"prog_id_fonctionnel": prog_id
|
|
||||||
}
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f" Échec: {e}")
|
|
||||||
print(f" Type erreur: {type(e).__name__}")
|
|
||||||
print(f" Code: {e.args if hasattr(e, 'args') else 'N/A'}")
|
|
||||||
|
|
||||||
# ==========================================
|
|
||||||
# 7. RÉSUMÉ ET RECOMMANDATIONS
|
|
||||||
# ==========================================
|
|
||||||
print("\n" + "="*70)
|
|
||||||
print("📊 RÉSUMÉ DU DIAGNOSTIC")
|
|
||||||
print("="*70)
|
|
||||||
|
|
||||||
print(f"\n📁 Installation détectée: {'OUI' if crystal_trouve else 'NON'}")
|
|
||||||
print(f"📦 DLL trouvées: {len(dll_trouvees)}/{len(dll_critiques)}")
|
|
||||||
print(f"📋 ProgID valides: {len(prog_ids_trouves)}")
|
|
||||||
print(f"🔧 Architecture: Python {python_arch}, Crystal {crystal_arch or 'INCONNUE'}")
|
|
||||||
|
|
||||||
if problemes:
|
|
||||||
print(f"\n PROBLÈMES DÉTECTÉS ({len(problemes)}):")
|
|
||||||
for i, pb in enumerate(problemes, 1):
|
|
||||||
print(f" {i}. {pb}")
|
|
||||||
|
|
||||||
if solutions:
|
|
||||||
print(f"\n💡 SOLUTIONS RECOMMANDÉES:")
|
|
||||||
for i, sol in enumerate(solutions, 1):
|
|
||||||
print(f" {i}. {sol}")
|
|
||||||
|
|
||||||
print("\n" + "="*70)
|
|
||||||
|
|
||||||
return {
|
|
||||||
"problemes": problemes,
|
|
||||||
"solutions": solutions,
|
|
||||||
"installe": crystal_trouve,
|
|
||||||
"dll_trouvees": list(dll_trouvees.keys()),
|
|
||||||
"prog_ids_valides": prog_ids_trouves,
|
|
||||||
"architecture_ok": python_arch == crystal_arch if crystal_arch else False
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
resultats = diagnostic_complet_crystal()
|
|
||||||
|
|
||||||
print("\n💾 Résultats sauvegardés dans diagnostic_crystal.txt")
|
|
||||||
|
|
||||||
# Sauvegarder dans fichier
|
|
||||||
with open("diagnostic_crystal.txt", "w", encoding="utf-8") as f:
|
|
||||||
f.write("="*70 + "\n")
|
|
||||||
f.write("DIAGNOSTIC CRYSTAL REPORTS\n")
|
|
||||||
f.write("="*70 + "\n\n")
|
|
||||||
|
|
||||||
f.write(f"Installation détectée: {resultats['installe']}\n")
|
|
||||||
f.write(f"DLL trouvées: {', '.join(resultats.get('dll_trouvees', []))}\n")
|
|
||||||
f.write(f"ProgID valides: {', '.join(resultats.get('prog_ids_valides', []))}\n")
|
|
||||||
f.write(f"Architecture OK: {resultats.get('architecture_ok', False)}\n\n")
|
|
||||||
|
|
||||||
f.write("PROBLÈMES:\n")
|
|
||||||
for pb in resultats['problemes']:
|
|
||||||
f.write(f" - {pb}\n")
|
|
||||||
|
|
||||||
f.write("\nSOLUTIONS:\n")
|
|
||||||
for sol in resultats['solutions']:
|
|
||||||
f.write(f" - {sol}\n")
|
|
||||||
|
|
@ -2,6 +2,7 @@ import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _extraire_article(article_obj):
|
def _extraire_article(article_obj):
|
||||||
try:
|
try:
|
||||||
data = {
|
data = {
|
||||||
|
|
@ -23,68 +24,64 @@ def _extraire_article(article_obj):
|
||||||
if code_barre1:
|
if code_barre1:
|
||||||
data["code_ean"] = code_barre1
|
data["code_ean"] = code_barre1
|
||||||
data["code_barre"] = code_barre1
|
data["code_barre"] = code_barre1
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["prix_vente"] = float(getattr(article_obj, "AR_PrixVen", 0.0))
|
data["prix_vente"] = float(getattr(article_obj, "AR_PrixVen", 0.0))
|
||||||
except:
|
except Exception:
|
||||||
data["prix_vente"] = 0.0
|
data["prix_vente"] = 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["prix_achat"] = float(getattr(article_obj, "AR_PrixAch", 0.0))
|
data["prix_achat"] = float(getattr(article_obj, "AR_PrixAch", 0.0))
|
||||||
except:
|
except Exception:
|
||||||
data["prix_achat"] = 0.0
|
data["prix_achat"] = 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["prix_revient"] = float(
|
data["prix_revient"] = float(getattr(article_obj, "AR_PrixRevient", 0.0))
|
||||||
getattr(article_obj, "AR_PrixRevient", 0.0)
|
except Exception:
|
||||||
)
|
|
||||||
except:
|
|
||||||
data["prix_revient"] = 0.0
|
data["prix_revient"] = 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["stock_reel"] = float(getattr(article_obj, "AR_Stock", 0.0))
|
data["stock_reel"] = float(getattr(article_obj, "AR_Stock", 0.0))
|
||||||
except:
|
except Exception:
|
||||||
data["stock_reel"] = 0.0
|
data["stock_reel"] = 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["stock_mini"] = float(getattr(article_obj, "AR_StockMini", 0.0))
|
data["stock_mini"] = float(getattr(article_obj, "AR_StockMini", 0.0))
|
||||||
except:
|
except Exception:
|
||||||
data["stock_mini"] = 0.0
|
data["stock_mini"] = 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["stock_maxi"] = float(getattr(article_obj, "AR_StockMaxi", 0.0))
|
data["stock_maxi"] = float(getattr(article_obj, "AR_StockMaxi", 0.0))
|
||||||
except:
|
except Exception:
|
||||||
data["stock_maxi"] = 0.0
|
data["stock_maxi"] = 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["stock_reserve"] = float(getattr(article_obj, "AR_QteCom", 0.0))
|
data["stock_reserve"] = float(getattr(article_obj, "AR_QteCom", 0.0))
|
||||||
except:
|
except Exception:
|
||||||
data["stock_reserve"] = 0.0
|
data["stock_reserve"] = 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["stock_commande"] = float(
|
data["stock_commande"] = float(getattr(article_obj, "AR_QteComFou", 0.0))
|
||||||
getattr(article_obj, "AR_QteComFou", 0.0)
|
except Exception:
|
||||||
)
|
|
||||||
except:
|
|
||||||
data["stock_commande"] = 0.0
|
data["stock_commande"] = 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["stock_disponible"] = data["stock_reel"] - data["stock_reserve"]
|
data["stock_disponible"] = data["stock_reel"] - data["stock_reserve"]
|
||||||
except:
|
except Exception:
|
||||||
data["stock_disponible"] = data["stock_reel"]
|
data["stock_disponible"] = data["stock_reel"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
commentaire = getattr(article_obj, "AR_Commentaire", "").strip()
|
commentaire = getattr(article_obj, "AR_Commentaire", "").strip()
|
||||||
data["description"] = commentaire
|
data["description"] = commentaire
|
||||||
except:
|
except Exception:
|
||||||
data["description"] = ""
|
data["description"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
design2 = getattr(article_obj, "AR_Design2", "").strip()
|
design2 = getattr(article_obj, "AR_Design2", "").strip()
|
||||||
data["designation_complementaire"] = design2
|
data["designation_complementaire"] = design2
|
||||||
except:
|
except Exception:
|
||||||
data["designation_complementaire"] = ""
|
data["designation_complementaire"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -95,7 +92,7 @@ def _extraire_article(article_obj):
|
||||||
1: "Prestation",
|
1: "Prestation",
|
||||||
2: "Divers",
|
2: "Divers",
|
||||||
}.get(type_art, "Inconnu")
|
}.get(type_art, "Inconnu")
|
||||||
except:
|
except Exception:
|
||||||
data["type_article"] = 0
|
data["type_article"] = 0
|
||||||
data["type_article_libelle"] = "Article"
|
data["type_article_libelle"] = "Article"
|
||||||
|
|
||||||
|
|
@ -113,11 +110,11 @@ def _extraire_article(article_obj):
|
||||||
).strip()
|
).strip()
|
||||||
else:
|
else:
|
||||||
data["famille_libelle"] = ""
|
data["famille_libelle"] = ""
|
||||||
except:
|
except Exception:
|
||||||
data["famille_libelle"] = ""
|
data["famille_libelle"] = ""
|
||||||
else:
|
else:
|
||||||
data["famille_libelle"] = ""
|
data["famille_libelle"] = ""
|
||||||
except:
|
except Exception:
|
||||||
data["famille_code"] = ""
|
data["famille_code"] = ""
|
||||||
data["famille_libelle"] = ""
|
data["famille_libelle"] = ""
|
||||||
|
|
||||||
|
|
@ -135,39 +132,39 @@ def _extraire_article(article_obj):
|
||||||
).strip()
|
).strip()
|
||||||
else:
|
else:
|
||||||
data["fournisseur_nom"] = ""
|
data["fournisseur_nom"] = ""
|
||||||
except:
|
except Exception:
|
||||||
data["fournisseur_nom"] = ""
|
data["fournisseur_nom"] = ""
|
||||||
else:
|
else:
|
||||||
data["fournisseur_nom"] = ""
|
data["fournisseur_nom"] = ""
|
||||||
except:
|
except Exception:
|
||||||
data["fournisseur_principal"] = ""
|
data["fournisseur_principal"] = ""
|
||||||
data["fournisseur_nom"] = ""
|
data["fournisseur_nom"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["unite_vente"] = getattr(article_obj, "AR_UniteVen", "").strip()
|
data["unite_vente"] = getattr(article_obj, "AR_UniteVen", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["unite_vente"] = ""
|
data["unite_vente"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["unite_achat"] = getattr(article_obj, "AR_UniteAch", "").strip()
|
data["unite_achat"] = getattr(article_obj, "AR_UniteAch", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["unite_achat"] = ""
|
data["unite_achat"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["poids"] = float(getattr(article_obj, "AR_Poids", 0.0))
|
data["poids"] = float(getattr(article_obj, "AR_Poids", 0.0))
|
||||||
except:
|
except Exception:
|
||||||
data["poids"] = 0.0
|
data["poids"] = 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["volume"] = float(getattr(article_obj, "AR_Volume", 0.0))
|
data["volume"] = float(getattr(article_obj, "AR_Volume", 0.0))
|
||||||
except:
|
except Exception:
|
||||||
data["volume"] = 0.0
|
data["volume"] = 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sommeil = getattr(article_obj, "AR_Sommeil", 0)
|
sommeil = getattr(article_obj, "AR_Sommeil", 0)
|
||||||
data["est_actif"] = sommeil == 0
|
data["est_actif"] = sommeil == 0
|
||||||
data["en_sommeil"] = sommeil == 1
|
data["en_sommeil"] = sommeil == 1
|
||||||
except:
|
except Exception:
|
||||||
data["est_actif"] = True
|
data["est_actif"] = True
|
||||||
data["en_sommeil"] = False
|
data["en_sommeil"] = False
|
||||||
|
|
||||||
|
|
@ -182,22 +179,22 @@ def _extraire_article(article_obj):
|
||||||
data["tva_taux"] = float(getattr(tva_obj, "TA_Taux", 20.0))
|
data["tva_taux"] = float(getattr(tva_obj, "TA_Taux", 20.0))
|
||||||
else:
|
else:
|
||||||
data["tva_taux"] = 20.0
|
data["tva_taux"] = 20.0
|
||||||
except:
|
except Exception:
|
||||||
data["tva_taux"] = 20.0
|
data["tva_taux"] = 20.0
|
||||||
except:
|
except Exception:
|
||||||
data["tva_code"] = ""
|
data["tva_code"] = ""
|
||||||
data["tva_taux"] = 20.0
|
data["tva_taux"] = 20.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
date_creation = getattr(article_obj, "AR_DateCreate", None)
|
date_creation = getattr(article_obj, "AR_DateCreate", None)
|
||||||
data["date_creation"] = str(date_creation) if date_creation else ""
|
data["date_creation"] = str(date_creation) if date_creation else ""
|
||||||
except:
|
except Exception:
|
||||||
data["date_creation"] = ""
|
data["date_creation"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
date_modif = getattr(article_obj, "AR_DateModif", None)
|
date_modif = getattr(article_obj, "AR_DateModif", None)
|
||||||
data["date_modification"] = str(date_modif) if date_modif else ""
|
data["date_modification"] = str(date_modif) if date_modif else ""
|
||||||
except:
|
except Exception:
|
||||||
data["date_modification"] = ""
|
data["date_modification"] = ""
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
from typing import Dict, List, Optional, Any
|
from typing import Dict, List
|
||||||
import win32com.client
|
import win32com.client
|
||||||
import logging
|
import logging
|
||||||
from utils.functions.functions import _safe_strip
|
from utils.functions.functions import _safe_strip
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_stock_emplacements(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_stock_emplacements(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement stock emplacements...")
|
logger.info(" → Enrichissement stock emplacements...")
|
||||||
|
|
||||||
references = [a["reference"] for a in articles if a["reference"]]
|
references = [a["reference"] for a in articles if a["reference"]]
|
||||||
if not references:
|
if not references:
|
||||||
|
|
@ -41,7 +42,8 @@ def _enrichir_stock_emplacements(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
if ref not in emplacements_map:
|
if ref not in emplacements_map:
|
||||||
emplacements_map[ref] = []
|
emplacements_map[ref] = []
|
||||||
|
|
||||||
emplacements_map[ref].append({
|
emplacements_map[ref].append(
|
||||||
|
{
|
||||||
"depot": _safe_strip(row[1]),
|
"depot": _safe_strip(row[1]),
|
||||||
"emplacement": _safe_strip(row[2]),
|
"emplacement": _safe_strip(row[2]),
|
||||||
"qte_stockee": float(row[3]) if row[3] else 0.0,
|
"qte_stockee": float(row[3]) if row[3] else 0.0,
|
||||||
|
|
@ -49,7 +51,8 @@ def _enrichir_stock_emplacements(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
"qte_a_controler": float(row[5]) if row[5] else 0.0,
|
"qte_a_controler": float(row[5]) if row[5] else 0.0,
|
||||||
"date_creation": row[6],
|
"date_creation": row[6],
|
||||||
"date_modification": row[7],
|
"date_modification": row[7],
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
for article in articles:
|
for article in articles:
|
||||||
article["emplacements"] = emplacements_map.get(article["reference"], [])
|
article["emplacements"] = emplacements_map.get(article["reference"], [])
|
||||||
|
|
@ -65,9 +68,10 @@ def _enrichir_stock_emplacements(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
article["nb_emplacements"] = 0
|
article["nb_emplacements"] = 0
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_gammes_articles(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_gammes_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement gammes articles...")
|
logger.info(" → Enrichissement gammes articles...")
|
||||||
|
|
||||||
references = [a["reference"] for a in articles if a["reference"]]
|
references = [a["reference"] for a in articles if a["reference"]]
|
||||||
if not references:
|
if not references:
|
||||||
|
|
@ -99,13 +103,15 @@ def _enrichir_gammes_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
if ref not in gammes_map:
|
if ref not in gammes_map:
|
||||||
gammes_map[ref] = []
|
gammes_map[ref] = []
|
||||||
|
|
||||||
gammes_map[ref].append({
|
gammes_map[ref].append(
|
||||||
|
{
|
||||||
"numero_gamme": int(row[1]) if row[1] else 0,
|
"numero_gamme": int(row[1]) if row[1] else 0,
|
||||||
"enumere": _safe_strip(row[2]),
|
"enumere": _safe_strip(row[2]),
|
||||||
"type_gamme": int(row[3]) if row[3] else 0,
|
"type_gamme": int(row[3]) if row[3] else 0,
|
||||||
"date_creation": row[4],
|
"date_creation": row[4],
|
||||||
"date_modification": row[5],
|
"date_modification": row[5],
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
for article in articles:
|
for article in articles:
|
||||||
article["gammes"] = gammes_map.get(article["reference"], [])
|
article["gammes"] = gammes_map.get(article["reference"], [])
|
||||||
|
|
@ -121,9 +127,10 @@ def _enrichir_gammes_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
article["nb_gammes"] = 0
|
article["nb_gammes"] = 0
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_tarifs_clients(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_tarifs_clients(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement tarifs clients...")
|
logger.info(" → Enrichissement tarifs clients...")
|
||||||
|
|
||||||
references = [a["reference"] for a in articles if a["reference"]]
|
references = [a["reference"] for a in articles if a["reference"]]
|
||||||
if not references:
|
if not references:
|
||||||
|
|
@ -171,7 +178,8 @@ def _enrichir_tarifs_clients(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
if ref not in tarifs_map:
|
if ref not in tarifs_map:
|
||||||
tarifs_map[ref] = []
|
tarifs_map[ref] = []
|
||||||
|
|
||||||
tarifs_map[ref].append({
|
tarifs_map[ref].append(
|
||||||
|
{
|
||||||
"categorie": int(row[1]) if row[1] else 0,
|
"categorie": int(row[1]) if row[1] else 0,
|
||||||
"client_num": _safe_strip(row[2]),
|
"client_num": _safe_strip(row[2]),
|
||||||
"prix_vente": float(row[3]) if row[3] else 0.0,
|
"prix_vente": float(row[3]) if row[3] else 0.0,
|
||||||
|
|
@ -193,7 +201,8 @@ def _enrichir_tarifs_clients(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
"date_application": row[19],
|
"date_application": row[19],
|
||||||
"date_creation": row[20],
|
"date_creation": row[20],
|
||||||
"date_modification": row[21],
|
"date_modification": row[21],
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
for article in articles:
|
for article in articles:
|
||||||
article["tarifs_clients"] = tarifs_map.get(article["reference"], [])
|
article["tarifs_clients"] = tarifs_map.get(article["reference"], [])
|
||||||
|
|
@ -209,9 +218,10 @@ def _enrichir_tarifs_clients(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
article["nb_tarifs_clients"] = 0
|
article["nb_tarifs_clients"] = 0
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_nomenclature(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_nomenclature(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement nomenclature...")
|
logger.info(" → Enrichissement nomenclature...")
|
||||||
|
|
||||||
references = [a["reference"] for a in articles if a["reference"]]
|
references = [a["reference"] for a in articles if a["reference"]]
|
||||||
if not references:
|
if not references:
|
||||||
|
|
@ -254,7 +264,8 @@ def _enrichir_nomenclature(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
if ref not in composants_map:
|
if ref not in composants_map:
|
||||||
composants_map[ref] = []
|
composants_map[ref] = []
|
||||||
|
|
||||||
composants_map[ref].append({
|
composants_map[ref].append(
|
||||||
|
{
|
||||||
"operation": _safe_strip(row[1]),
|
"operation": _safe_strip(row[1]),
|
||||||
"code_ressource": _safe_strip(row[2]),
|
"code_ressource": _safe_strip(row[2]),
|
||||||
"temps": float(row[3]) if row[3] else 0.0,
|
"temps": float(row[3]) if row[3] else 0.0,
|
||||||
|
|
@ -271,7 +282,8 @@ def _enrichir_nomenclature(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
"type_chevauche": int(row[14]) if row[14] else 0,
|
"type_chevauche": int(row[14]) if row[14] else 0,
|
||||||
"date_creation": row[15],
|
"date_creation": row[15],
|
||||||
"date_modification": row[16],
|
"date_modification": row[16],
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
for article in articles:
|
for article in articles:
|
||||||
article["composants"] = composants_map.get(article["reference"], [])
|
article["composants"] = composants_map.get(article["reference"], [])
|
||||||
|
|
@ -287,9 +299,10 @@ def _enrichir_nomenclature(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
article["nb_composants"] = 0
|
article["nb_composants"] = 0
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_compta_articles(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_compta_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement comptabilité articles...")
|
logger.info(" → Enrichissement comptabilité articles...")
|
||||||
|
|
||||||
references = [a["reference"] for a in articles if a["reference"]]
|
references = [a["reference"] for a in articles if a["reference"]]
|
||||||
if not references:
|
if not references:
|
||||||
|
|
@ -357,7 +370,9 @@ def _enrichir_compta_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
compta_map[ref][type_key].append(compta_entry)
|
compta_map[ref][type_key].append(compta_entry)
|
||||||
|
|
||||||
for article in articles:
|
for article in articles:
|
||||||
compta = compta_map.get(article["reference"], {"vente": [], "achat": [], "stock": []})
|
compta = compta_map.get(
|
||||||
|
article["reference"], {"vente": [], "achat": [], "stock": []}
|
||||||
|
)
|
||||||
article["compta_vente"] = compta["vente"]
|
article["compta_vente"] = compta["vente"]
|
||||||
article["compta_achat"] = compta["achat"]
|
article["compta_achat"] = compta["achat"]
|
||||||
article["compta_stock"] = compta["stock"]
|
article["compta_stock"] = compta["stock"]
|
||||||
|
|
@ -373,9 +388,10 @@ def _enrichir_compta_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
article["compta_stock"] = []
|
article["compta_stock"] = []
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_fournisseurs_multiples(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_fournisseurs_multiples(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement fournisseurs multiples...")
|
logger.info(" → Enrichissement fournisseurs multiples...")
|
||||||
|
|
||||||
references = [a["reference"] for a in articles if a["reference"]]
|
references = [a["reference"] for a in articles if a["reference"]]
|
||||||
if not references:
|
if not references:
|
||||||
|
|
@ -426,7 +442,8 @@ def _enrichir_fournisseurs_multiples(articles: List[Dict], cursor) -> List[Dict]
|
||||||
if ref not in fournisseurs_map:
|
if ref not in fournisseurs_map:
|
||||||
fournisseurs_map[ref] = []
|
fournisseurs_map[ref] = []
|
||||||
|
|
||||||
fournisseurs_map[ref].append({
|
fournisseurs_map[ref].append(
|
||||||
|
{
|
||||||
"fournisseur_num": _safe_strip(row[1]),
|
"fournisseur_num": _safe_strip(row[1]),
|
||||||
"ref_fournisseur": _safe_strip(row[2]),
|
"ref_fournisseur": _safe_strip(row[2]),
|
||||||
"prix_achat": float(row[3]) if row[3] else 0.0,
|
"prix_achat": float(row[3]) if row[3] else 0.0,
|
||||||
|
|
@ -451,7 +468,8 @@ def _enrichir_fournisseurs_multiples(articles: List[Dict], cursor) -> List[Dict]
|
||||||
"date_application": row[22],
|
"date_application": row[22],
|
||||||
"date_creation": row[23],
|
"date_creation": row[23],
|
||||||
"date_modification": row[24],
|
"date_modification": row[24],
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
for article in articles:
|
for article in articles:
|
||||||
article["fournisseurs"] = fournisseurs_map.get(article["reference"], [])
|
article["fournisseurs"] = fournisseurs_map.get(article["reference"], [])
|
||||||
|
|
@ -467,9 +485,10 @@ def _enrichir_fournisseurs_multiples(articles: List[Dict], cursor) -> List[Dict]
|
||||||
article["nb_fournisseurs"] = 0
|
article["nb_fournisseurs"] = 0
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_depots_details(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_depots_details(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement détails dépôts...")
|
logger.info(" → Enrichissement détails dépôts...")
|
||||||
|
|
||||||
query = """
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
|
|
@ -530,16 +549,17 @@ def _enrichir_depots_details(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
if depot_num and depot_num in depots_map:
|
if depot_num and depot_num in depots_map:
|
||||||
empl.update(depots_map[depot_num])
|
empl.update(depots_map[depot_num])
|
||||||
|
|
||||||
logger.info(f" Emplacements enrichis avec détails dépôts")
|
logger.info(" Emplacements enrichis avec détails dépôts")
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f" Erreur détails dépôts: {e}")
|
logger.error(f" Erreur détails dépôts: {e}")
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_emplacements_details(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_emplacements_details(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement détails emplacements...")
|
logger.info(" → Enrichissement détails emplacements...")
|
||||||
|
|
||||||
query = """
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
|
|
@ -582,16 +602,17 @@ def _enrichir_emplacements_details(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
if key in emplacements_map:
|
if key in emplacements_map:
|
||||||
empl.update(emplacements_map[key])
|
empl.update(emplacements_map[key])
|
||||||
|
|
||||||
logger.info(f" Emplacements enrichis avec détails")
|
logger.info(" Emplacements enrichis avec détails")
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f" Erreur détails emplacements: {e}")
|
logger.error(f" Erreur détails emplacements: {e}")
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_gammes_enumeres(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_gammes_enumeres(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement énumérés gammes...")
|
logger.info(" → Enrichissement énumérés gammes...")
|
||||||
|
|
||||||
query_pgamme = "SELECT G_Intitule, G_Type FROM P_GAMME ORDER BY G_Type"
|
query_pgamme = "SELECT G_Intitule, G_Type FROM P_GAMME ORDER BY G_Type"
|
||||||
cursor.execute(query_pgamme)
|
cursor.execute(query_pgamme)
|
||||||
|
|
@ -647,16 +668,17 @@ def _enrichir_gammes_enumeres(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
if key in enumeres_map:
|
if key in enumeres_map:
|
||||||
gamme.update(enumeres_map[key])
|
gamme.update(enumeres_map[key])
|
||||||
|
|
||||||
logger.info(f" Gammes enrichies avec énumérés")
|
logger.info(" Gammes enrichies avec énumérés")
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f" Erreur énumérés gammes: {e}")
|
logger.error(f" Erreur énumérés gammes: {e}")
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_references_enumerees(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_references_enumerees(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement références énumérées...")
|
logger.info(" → Enrichissement références énumérées...")
|
||||||
|
|
||||||
references = [a["reference"] for a in articles if a["reference"]]
|
references = [a["reference"] for a in articles if a["reference"]]
|
||||||
if not references:
|
if not references:
|
||||||
|
|
@ -693,7 +715,8 @@ def _enrichir_references_enumerees(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
if ref not in refs_enum_map:
|
if ref not in refs_enum_map:
|
||||||
refs_enum_map[ref] = []
|
refs_enum_map[ref] = []
|
||||||
|
|
||||||
refs_enum_map[ref].append({
|
refs_enum_map[ref].append(
|
||||||
|
{
|
||||||
"gamme_1": int(row[1]) if row[1] else 0,
|
"gamme_1": int(row[1]) if row[1] else 0,
|
||||||
"gamme_2": int(row[2]) if row[2] else 0,
|
"gamme_2": int(row[2]) if row[2] else 0,
|
||||||
"reference_enumeree": _safe_strip(row[3]),
|
"reference_enumeree": _safe_strip(row[3]),
|
||||||
|
|
@ -704,7 +727,8 @@ def _enrichir_references_enumerees(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
"en_sommeil": bool(row[8]),
|
"en_sommeil": bool(row[8]),
|
||||||
"date_creation": row[9],
|
"date_creation": row[9],
|
||||||
"date_modification": row[10],
|
"date_modification": row[10],
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
for article in articles:
|
for article in articles:
|
||||||
article["refs_enumerees"] = refs_enum_map.get(article["reference"], [])
|
article["refs_enumerees"] = refs_enum_map.get(article["reference"], [])
|
||||||
|
|
@ -720,9 +744,10 @@ def _enrichir_references_enumerees(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
article["nb_refs_enumerees"] = 0
|
article["nb_refs_enumerees"] = 0
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_medias_articles(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_medias_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement médias articles...")
|
logger.info(" → Enrichissement médias articles...")
|
||||||
|
|
||||||
references = [a["reference"] for a in articles if a["reference"]]
|
references = [a["reference"] for a in articles if a["reference"]]
|
||||||
if not references:
|
if not references:
|
||||||
|
|
@ -756,7 +781,8 @@ def _enrichir_medias_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
if ref not in medias_map:
|
if ref not in medias_map:
|
||||||
medias_map[ref] = []
|
medias_map[ref] = []
|
||||||
|
|
||||||
medias_map[ref].append({
|
medias_map[ref].append(
|
||||||
|
{
|
||||||
"commentaire": _safe_strip(row[1]),
|
"commentaire": _safe_strip(row[1]),
|
||||||
"fichier": _safe_strip(row[2]),
|
"fichier": _safe_strip(row[2]),
|
||||||
"type_mime": _safe_strip(row[3]),
|
"type_mime": _safe_strip(row[3]),
|
||||||
|
|
@ -764,7 +790,8 @@ def _enrichir_medias_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
"ged_id": _safe_strip(row[5]),
|
"ged_id": _safe_strip(row[5]),
|
||||||
"date_creation": row[6],
|
"date_creation": row[6],
|
||||||
"date_modification": row[7],
|
"date_modification": row[7],
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
for article in articles:
|
for article in articles:
|
||||||
article["medias"] = medias_map.get(article["reference"], [])
|
article["medias"] = medias_map.get(article["reference"], [])
|
||||||
|
|
@ -780,9 +807,10 @@ def _enrichir_medias_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
article["nb_medias"] = 0
|
article["nb_medias"] = 0
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_prix_gammes(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_prix_gammes(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement prix par gammes...")
|
logger.info(" → Enrichissement prix par gammes...")
|
||||||
|
|
||||||
references = [a["reference"] for a in articles if a["reference"]]
|
references = [a["reference"] for a in articles if a["reference"]]
|
||||||
if not references:
|
if not references:
|
||||||
|
|
@ -815,14 +843,16 @@ def _enrichir_prix_gammes(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
if ref not in prix_gammes_map:
|
if ref not in prix_gammes_map:
|
||||||
prix_gammes_map[ref] = []
|
prix_gammes_map[ref] = []
|
||||||
|
|
||||||
prix_gammes_map[ref].append({
|
prix_gammes_map[ref].append(
|
||||||
|
{
|
||||||
"gamme_1": int(row[1]) if row[1] else 0,
|
"gamme_1": int(row[1]) if row[1] else 0,
|
||||||
"gamme_2": int(row[2]) if row[2] else 0,
|
"gamme_2": int(row[2]) if row[2] else 0,
|
||||||
"prix_net": float(row[3]) if row[3] else 0.0,
|
"prix_net": float(row[3]) if row[3] else 0.0,
|
||||||
"cout_standard": float(row[4]) if row[4] else 0.0,
|
"cout_standard": float(row[4]) if row[4] else 0.0,
|
||||||
"date_creation": row[5],
|
"date_creation": row[5],
|
||||||
"date_modification": row[6],
|
"date_modification": row[6],
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
for article in articles:
|
for article in articles:
|
||||||
article["prix_gammes"] = prix_gammes_map.get(article["reference"], [])
|
article["prix_gammes"] = prix_gammes_map.get(article["reference"], [])
|
||||||
|
|
@ -838,9 +868,10 @@ def _enrichir_prix_gammes(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
article["nb_prix_gammes"] = 0
|
article["nb_prix_gammes"] = 0
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_conditionnements(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_conditionnements(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement conditionnements...")
|
logger.info(" → Enrichissement conditionnements...")
|
||||||
|
|
||||||
query = """
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
|
|
@ -882,13 +913,14 @@ def _enrichir_conditionnements(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
article["conditionnement_edi"] = cond_data["edi_code"]
|
article["conditionnement_edi"] = cond_data["edi_code"]
|
||||||
break
|
break
|
||||||
|
|
||||||
logger.info(f" Conditionnements enrichis")
|
logger.info(" Conditionnements enrichis")
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f" Erreur conditionnements: {e}")
|
logger.error(f" Erreur conditionnements: {e}")
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _mapper_article_depuis_row(row_data: Dict, colonnes_config: Dict) -> Dict:
|
def _mapper_article_depuis_row(row_data: Dict, colonnes_config: Dict) -> Dict:
|
||||||
article = {}
|
article = {}
|
||||||
|
|
||||||
|
|
@ -897,13 +929,13 @@ def _mapper_article_depuis_row(row_data: Dict, colonnes_config: Dict) -> Dict:
|
||||||
if val is None:
|
if val is None:
|
||||||
return default
|
return default
|
||||||
|
|
||||||
if convert_type == float:
|
if isinstance(convert_type, float):
|
||||||
return float(val) if val not in (None, "") else (default or 0.0)
|
return float(val) if val not in (None, "") else (default or 0.0)
|
||||||
elif convert_type == int:
|
elif isinstance(convert_type, int):
|
||||||
return int(val) if val not in (None, "") else (default or 0)
|
return int(val) if val not in (None, "") else (default or 0)
|
||||||
elif convert_type == bool:
|
elif isinstance(convert_type, bool):
|
||||||
return bool(val) if val not in (None, "") else (default or False)
|
return bool(val) if val not in (None, "") else (default or False)
|
||||||
elif convert_type == str:
|
elif isinstance(convert_type, str):
|
||||||
return _safe_strip(val)
|
return _safe_strip(val)
|
||||||
|
|
||||||
return val
|
return val
|
||||||
|
|
@ -956,8 +988,8 @@ def _mapper_article_depuis_row(row_data: Dict, colonnes_config: Dict) -> Dict:
|
||||||
article["qte_operatoire"] = get_val("AR_QteOperatoire", 0.0, float)
|
article["qte_operatoire"] = get_val("AR_QteOperatoire", 0.0, float)
|
||||||
|
|
||||||
sommeil = get_val("AR_Sommeil", 0, int)
|
sommeil = get_val("AR_Sommeil", 0, int)
|
||||||
article["est_actif"] = (sommeil == 0)
|
article["est_actif"] = sommeil == 0
|
||||||
article["en_sommeil"] = (sommeil == 1)
|
article["en_sommeil"] = sommeil == 1
|
||||||
article["article_substitut"] = get_val("AR_Substitut", convert_type=str)
|
article["article_substitut"] = get_val("AR_Substitut", convert_type=str)
|
||||||
article["soumis_escompte"] = get_val("AR_Escompte", False, bool)
|
article["soumis_escompte"] = get_val("AR_Escompte", False, bool)
|
||||||
article["delai"] = get_val("AR_Delai", 0, int)
|
article["delai"] = get_val("AR_Delai", 0, int)
|
||||||
|
|
@ -1000,21 +1032,31 @@ def _mapper_article_depuis_row(row_data: Dict, colonnes_config: Dict) -> Dict:
|
||||||
article["langue_1"] = get_val("AR_Langue1", convert_type=str)
|
article["langue_1"] = get_val("AR_Langue1", convert_type=str)
|
||||||
article["langue_2"] = get_val("AR_Langue2", convert_type=str)
|
article["langue_2"] = get_val("AR_Langue2", convert_type=str)
|
||||||
|
|
||||||
article["frais_01_denomination"] = get_val("AR_Frais01FR_Denomination", convert_type=str)
|
article["frais_01_denomination"] = get_val(
|
||||||
article["frais_02_denomination"] = get_val("AR_Frais02FR_Denomination", convert_type=str)
|
"AR_Frais01FR_Denomination", convert_type=str
|
||||||
article["frais_03_denomination"] = get_val("AR_Frais03FR_Denomination", convert_type=str)
|
)
|
||||||
|
article["frais_02_denomination"] = get_val(
|
||||||
|
"AR_Frais02FR_Denomination", convert_type=str
|
||||||
|
)
|
||||||
|
article["frais_03_denomination"] = get_val(
|
||||||
|
"AR_Frais03FR_Denomination", convert_type=str
|
||||||
|
)
|
||||||
|
|
||||||
article["marque_commerciale"] = get_val("Marque commerciale", convert_type=str)
|
article["marque_commerciale"] = get_val("Marque commerciale", convert_type=str)
|
||||||
|
|
||||||
objectif_val = get_val("Objectif / Qtés vendues")
|
objectif_val = get_val("Objectif / Qtés vendues")
|
||||||
if objectif_val is not None:
|
if objectif_val is not None:
|
||||||
article["objectif_qtes_vendues"] = str(float(objectif_val)) if objectif_val not in ("", 0, 0.0) else None
|
article["objectif_qtes_vendues"] = (
|
||||||
|
str(float(objectif_val)) if objectif_val not in ("", 0, 0.0) else None
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
article["objectif_qtes_vendues"] = None
|
article["objectif_qtes_vendues"] = None
|
||||||
|
|
||||||
pourcentage_val = get_val("Pourcentage teneur en or")
|
pourcentage_val = get_val("Pourcentage teneur en or")
|
||||||
if pourcentage_val is not None:
|
if pourcentage_val is not None:
|
||||||
article["pourcentage_or"] = str(float(pourcentage_val)) if pourcentage_val not in ("", 0, 0.0) else None
|
article["pourcentage_or"] = (
|
||||||
|
str(float(pourcentage_val)) if pourcentage_val not in ("", 0, 0.0) else None
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
article["pourcentage_or"] = None
|
article["pourcentage_or"] = None
|
||||||
|
|
||||||
|
|
@ -1053,6 +1095,7 @@ def _mapper_article_depuis_row(row_data: Dict, colonnes_config: Dict) -> Dict:
|
||||||
|
|
||||||
return article
|
return article
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_stocks_articles(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_stocks_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
"""Enrichit les articles avec les données de stock depuis F_ARTSTOCK"""
|
"""Enrichit les articles avec les données de stock depuis F_ARTSTOCK"""
|
||||||
try:
|
try:
|
||||||
|
|
@ -1108,15 +1151,21 @@ def _enrichir_stocks_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
logger.error(f" Erreur enrichissement stocks: {e}", exc_info=True)
|
logger.error(f" Erreur enrichissement stocks: {e}", exc_info=True)
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_fournisseurs_articles(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_fournisseurs_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
"""Enrichit les articles avec le nom du fournisseur principal"""
|
"""Enrichit les articles avec le nom du fournisseur principal"""
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement fournisseurs...")
|
logger.info(" → Enrichissement fournisseurs...")
|
||||||
|
|
||||||
nums_fournisseurs = list(set([
|
nums_fournisseurs = list(
|
||||||
a["fournisseur_principal"] for a in articles
|
set(
|
||||||
|
[
|
||||||
|
a["fournisseur_principal"]
|
||||||
|
for a in articles
|
||||||
if a.get("fournisseur_principal") and a["fournisseur_principal"] > 0
|
if a.get("fournisseur_principal") and a["fournisseur_principal"] > 0
|
||||||
]))
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if not nums_fournisseurs:
|
if not nums_fournisseurs:
|
||||||
logger.warning(" ⚠ Aucun numéro de fournisseur trouvé dans les articles")
|
logger.warning(" ⚠ Aucun numéro de fournisseur trouvé dans les articles")
|
||||||
|
|
@ -1144,17 +1193,24 @@ def _enrichir_fournisseurs_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
logger.info(f" → {len(fournisseur_rows)} fournisseurs trouvés dans F_COMPTET")
|
logger.info(f" → {len(fournisseur_rows)} fournisseurs trouvés dans F_COMPTET")
|
||||||
|
|
||||||
if len(fournisseur_rows) == 0:
|
if len(fournisseur_rows) == 0:
|
||||||
logger.warning(f" ⚠ Aucun fournisseur trouvé pour CT_Type=1 et CT_Num IN {nums_fournisseurs[:5]}")
|
logger.warning(
|
||||||
cursor.execute(f"SELECT CT_Num, CT_Type FROM F_COMPTET WHERE CT_Num IN ({placeholders})", nums_fournisseurs)
|
f" ⚠ Aucun fournisseur trouvé pour CT_Type=1 et CT_Num IN {nums_fournisseurs[:5]}"
|
||||||
|
)
|
||||||
|
cursor.execute(
|
||||||
|
f"SELECT CT_Num, CT_Type FROM F_COMPTET WHERE CT_Num IN ({placeholders})",
|
||||||
|
nums_fournisseurs,
|
||||||
|
)
|
||||||
tous_types = cursor.fetchall()
|
tous_types = cursor.fetchall()
|
||||||
if tous_types:
|
if tous_types:
|
||||||
logger.info(f" → Trouvé {len(tous_types)} comptes (tous types) : {[(r[0], r[1]) for r in tous_types[:5]]}")
|
logger.info(
|
||||||
|
f" → Trouvé {len(tous_types)} comptes (tous types) : {[(r[0], r[1]) for r in tous_types[:5]]}"
|
||||||
|
)
|
||||||
|
|
||||||
fournisseur_map = {}
|
fournisseur_map = {}
|
||||||
for fourn_row in fournisseur_rows:
|
for fourn_row in fournisseur_rows:
|
||||||
num = int(fourn_row[0]) # CT_Num
|
num = int(fourn_row[0])
|
||||||
nom = _safe_strip(fourn_row[1]) # CT_Intitule
|
nom = _safe_strip(fourn_row[1])
|
||||||
type_ct = int(fourn_row[2]) # CT_Type
|
type_ct = int(fourn_row[2])
|
||||||
fournisseur_map[num] = nom
|
fournisseur_map[num] = nom
|
||||||
logger.debug(f" → Fournisseur mappé : {num} = {nom} (Type={type_ct})")
|
logger.debug(f" → Fournisseur mappé : {num} = {nom} (Type={type_ct})")
|
||||||
|
|
||||||
|
|
@ -1177,22 +1233,24 @@ def _enrichir_fournisseurs_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
article["fournisseur_nom"] = None
|
article["fournisseur_nom"] = None
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_familles_articles(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_familles_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
"""Enrichit les articles avec les informations de famille depuis F_FAMILLE"""
|
"""Enrichit les articles avec les informations de famille depuis F_FAMILLE"""
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement familles pour {len(articles)} articles...")
|
logger.info(f" → Enrichissement familles pour {len(articles)} articles...")
|
||||||
|
|
||||||
codes_familles_bruts = [
|
codes_familles_bruts = [
|
||||||
a.get("famille_code") for a in articles
|
a.get("famille_code")
|
||||||
|
for a in articles
|
||||||
if a.get("famille_code") not in (None, "", " ")
|
if a.get("famille_code") not in (None, "", " ")
|
||||||
]
|
]
|
||||||
|
|
||||||
if codes_familles_bruts:
|
if codes_familles_bruts:
|
||||||
logger.info(f" → Exemples de codes familles : {codes_familles_bruts[:5]}")
|
logger.info(f" → Exemples de codes familles : {codes_familles_bruts[:5]}")
|
||||||
|
|
||||||
codes_familles = list(set([
|
codes_familles = list(
|
||||||
str(code).strip() for code in codes_familles_bruts if code
|
set([str(code).strip() for code in codes_familles_bruts if code])
|
||||||
]))
|
)
|
||||||
|
|
||||||
if not codes_familles:
|
if not codes_familles:
|
||||||
logger.warning(" ⚠ Aucun code famille trouvé dans les articles")
|
logger.warning(" ⚠ Aucun code famille trouvé dans les articles")
|
||||||
|
|
@ -1236,9 +1294,14 @@ def _enrichir_familles_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
"FA_Criticite",
|
"FA_Criticite",
|
||||||
]
|
]
|
||||||
|
|
||||||
colonnes_a_lire = [col for col in colonnes_souhaitees if col in colonnes_disponibles]
|
colonnes_a_lire = [
|
||||||
|
col for col in colonnes_souhaitees if col in colonnes_disponibles
|
||||||
|
]
|
||||||
|
|
||||||
if "FA_CodeFamille" not in colonnes_a_lire or "FA_Intitule" not in colonnes_a_lire:
|
if (
|
||||||
|
"FA_CodeFamille" not in colonnes_a_lire
|
||||||
|
or "FA_Intitule" not in colonnes_a_lire
|
||||||
|
):
|
||||||
logger.error(" Colonnes essentielles manquantes !")
|
logger.error(" Colonnes essentielles manquantes !")
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
@ -1308,6 +1371,7 @@ def _enrichir_familles_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
_init_champs_famille_vides(article)
|
_init_champs_famille_vides(article)
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _init_champs_famille_vides(article: Dict):
|
def _init_champs_famille_vides(article: Dict):
|
||||||
"""Initialise les champs famille à None/0"""
|
"""Initialise les champs famille à None/0"""
|
||||||
article["famille_libelle"] = None
|
article["famille_libelle"] = None
|
||||||
|
|
@ -1326,15 +1390,15 @@ def _init_champs_famille_vides(article: Dict):
|
||||||
article["famille_hors_stat"] = None
|
article["famille_hors_stat"] = None
|
||||||
article["famille_pays"] = None
|
article["famille_pays"] = None
|
||||||
|
|
||||||
|
|
||||||
def _enrichir_tva_articles(articles: List[Dict], cursor) -> List[Dict]:
|
def _enrichir_tva_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
"""Enrichit les articles avec le taux de TVA"""
|
"""Enrichit les articles avec le taux de TVA"""
|
||||||
try:
|
try:
|
||||||
logger.info(f" → Enrichissement TVA...")
|
logger.info(" → Enrichissement TVA...")
|
||||||
|
|
||||||
codes_tva = list(set([
|
codes_tva = list(
|
||||||
a["code_fiscal"] for a in articles
|
set([a["code_fiscal"] for a in articles if a.get("code_fiscal")])
|
||||||
if a.get("code_fiscal")
|
)
|
||||||
]))
|
|
||||||
|
|
||||||
if not codes_tva:
|
if not codes_tva:
|
||||||
for article in articles:
|
for article in articles:
|
||||||
|
|
@ -1379,24 +1443,22 @@ def _enrichir_tva_articles(articles: List[Dict], cursor) -> List[Dict]:
|
||||||
article["tva_taux"] = None
|
article["tva_taux"] = None
|
||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def _get_type_article_libelle(type_val: int) -> str:
|
def _get_type_article_libelle(type_val: int) -> str:
|
||||||
"""Retourne le libellé du type d'article"""
|
"""Retourne le libellé du type d'article"""
|
||||||
types = {
|
types = {0: "Article", 1: "Prestation", 2: "Divers / Frais", 3: "Nomenclature"}
|
||||||
0: "Article",
|
|
||||||
1: "Prestation",
|
|
||||||
2: "Divers / Frais",
|
|
||||||
3: "Nomenclature"
|
|
||||||
}
|
|
||||||
return types.get(type_val, f"Type {type_val}")
|
return types.get(type_val, f"Type {type_val}")
|
||||||
|
|
||||||
|
|
||||||
def _cast_article(persist_obj):
|
def _cast_article(persist_obj):
|
||||||
try:
|
try:
|
||||||
obj = win32com.client.CastTo(persist_obj, "IBOArticle3")
|
obj = win32com.client.CastTo(persist_obj, "IBOArticle3")
|
||||||
obj.Read()
|
obj.Read()
|
||||||
return obj
|
return obj
|
||||||
except:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"_enrichir_stock_emplacements",
|
"_enrichir_stock_emplacements",
|
||||||
"_enrichir_gammes_articles",
|
"_enrichir_gammes_articles",
|
||||||
|
|
@ -1417,5 +1479,5 @@ __all__ = [
|
||||||
"_enrichir_familles_articles",
|
"_enrichir_familles_articles",
|
||||||
"_init_champs_famille_vides",
|
"_init_champs_famille_vides",
|
||||||
"_enrichir_tva_articles",
|
"_enrichir_tva_articles",
|
||||||
"_cast_article"
|
"_cast_article",
|
||||||
]
|
]
|
||||||
|
|
@ -2,10 +2,10 @@ import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def verifier_stock_suffisant(article_ref, quantite, cursor, depot=None):
|
def verifier_stock_suffisant(article_ref, quantite, cursor, depot=None):
|
||||||
"""Version thread-safe avec lock SQL"""
|
"""Version thread-safe avec lock SQL"""
|
||||||
try:
|
try:
|
||||||
|
|
||||||
cursor.execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE")
|
cursor.execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE")
|
||||||
cursor.execute("BEGIN TRANSACTION")
|
cursor.execute("BEGIN TRANSACTION")
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ def verifier_stock_suffisant(article_ref, quantite, cursor, depot=None):
|
||||||
"quantite_demandee": quantite,
|
"quantite_demandee": quantite,
|
||||||
}
|
}
|
||||||
|
|
||||||
except:
|
except Exception:
|
||||||
cursor.execute("ROLLBACK")
|
cursor.execute("ROLLBACK")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _rechercher_devis_dans_liste(numero_devis, factory_doc):
|
def _rechercher_devis_dans_liste(numero_devis, factory_doc):
|
||||||
"""Recherche un devis dans les 100 premiers éléments de la liste."""
|
"""Recherche un devis dans les 100 premiers éléments de la liste."""
|
||||||
index = 1
|
index = 1
|
||||||
|
|
@ -23,11 +24,12 @@ def _rechercher_devis_dans_liste(numero_devis, factory_doc):
|
||||||
return persist_test
|
return persist_test
|
||||||
|
|
||||||
index += 1
|
index += 1
|
||||||
except:
|
except Exception:
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _recuperer_numero_devis(process, doc):
|
def _recuperer_numero_devis(process, doc):
|
||||||
"""Récupère le numéro du devis créé via plusieurs méthodes."""
|
"""Récupère le numéro du devis créé via plusieurs méthodes."""
|
||||||
numero_devis = None
|
numero_devis = None
|
||||||
|
|
@ -38,7 +40,7 @@ def _recuperer_numero_devis(process, doc):
|
||||||
doc_result = win32com.client.CastTo(doc_result, "IBODocumentVente3")
|
doc_result = win32com.client.CastTo(doc_result, "IBODocumentVente3")
|
||||||
doc_result.Read()
|
doc_result.Read()
|
||||||
numero_devis = getattr(doc_result, "DO_Piece", "")
|
numero_devis = getattr(doc_result, "DO_Piece", "")
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not numero_devis:
|
if not numero_devis:
|
||||||
|
|
@ -50,12 +52,10 @@ def _recuperer_numero_devis(process, doc):
|
||||||
doc.Write()
|
doc.Write()
|
||||||
doc.Read()
|
doc.Read()
|
||||||
numero_devis = getattr(doc, "DO_Piece", "")
|
numero_devis = getattr(doc, "DO_Piece", "")
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return numero_devis
|
return numero_devis
|
||||||
|
|
||||||
__all__ = [
|
|
||||||
"_recuperer_numero_devis",
|
__all__ = ["_recuperer_numero_devis", "_rechercher_devis_dans_liste"]
|
||||||
"_rechercher_devis_dans_liste"
|
|
||||||
]
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from typing import Dict, List, Optional, Any
|
from typing import Dict, List, Optional, Any
|
||||||
|
|
||||||
|
|
||||||
def _extraire_infos_devis(doc, numero: str, champs_modifies: list) -> Dict:
|
def _extraire_infos_devis(doc, numero: str, champs_modifies: list) -> Dict:
|
||||||
"""Extrait les informations complètes du devis."""
|
"""Extrait les informations complètes du devis."""
|
||||||
total_ht = float(getattr(doc, "DO_TotalHT", 0.0))
|
total_ht = float(getattr(doc, "DO_TotalHT", 0.0))
|
||||||
|
|
@ -12,7 +13,7 @@ def _extraire_infos_devis(doc, numero: str, champs_modifies: list) -> Dict:
|
||||||
date_doc = getattr(doc, "DO_Date", None)
|
date_doc = getattr(doc, "DO_Date", None)
|
||||||
if date_doc:
|
if date_doc:
|
||||||
date_devis = date_doc.strftime("%Y-%m-%d")
|
date_devis = date_doc.strftime("%Y-%m-%d")
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
date_livraison = None
|
date_livraison = None
|
||||||
|
|
@ -20,7 +21,7 @@ def _extraire_infos_devis(doc, numero: str, champs_modifies: list) -> Dict:
|
||||||
date_livr = getattr(doc, "DO_DateLivr", None)
|
date_livr = getattr(doc, "DO_DateLivr", None)
|
||||||
if date_livr:
|
if date_livr:
|
||||||
date_livraison = date_livr.strftime("%Y-%m-%d")
|
date_livraison = date_livr.strftime("%Y-%m-%d")
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
client_code = ""
|
client_code = ""
|
||||||
|
|
@ -29,7 +30,7 @@ def _extraire_infos_devis(doc, numero: str, champs_modifies: list) -> Dict:
|
||||||
if client_obj:
|
if client_obj:
|
||||||
client_obj.Read()
|
client_obj.Read()
|
||||||
client_code = getattr(client_obj, "CT_Num", "")
|
client_code = getattr(client_obj, "CT_Num", "")
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -44,6 +45,7 @@ def _extraire_infos_devis(doc, numero: str, champs_modifies: list) -> Dict:
|
||||||
"client_code": client_code,
|
"client_code": client_code,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"_extraire_infos_devis",
|
"_extraire_infos_devis",
|
||||||
]
|
]
|
||||||
|
|
@ -2,14 +2,16 @@ import win32com.client
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
from utils.functions.functions import (
|
from utils.functions.functions import (
|
||||||
_convertir_type_depuis_sql,
|
_convertir_type_depuis_sql,
|
||||||
_convertir_type_pour_sql,
|
_convertir_type_pour_sql,
|
||||||
_safe_strip
|
_safe_strip,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _afficher_etat_document(doc, titre: str):
|
def _afficher_etat_document(doc, titre: str):
|
||||||
"""Affiche l'état complet d'un document."""
|
"""Affiche l'état complet d'un document."""
|
||||||
logger.info("-" * 80)
|
logger.info("-" * 80)
|
||||||
|
|
@ -20,12 +22,12 @@ def _afficher_etat_document(doc, titre: str):
|
||||||
logger.info(f" DO_Ref: '{getattr(doc, 'DO_Ref', 'N/A')}'")
|
logger.info(f" DO_Ref: '{getattr(doc, 'DO_Ref', 'N/A')}'")
|
||||||
logger.info(f" DO_Statut: {getattr(doc, 'DO_Statut', 'N/A')}")
|
logger.info(f" DO_Statut: {getattr(doc, 'DO_Statut', 'N/A')}")
|
||||||
|
|
||||||
date_doc = getattr(doc, 'DO_Date', None)
|
date_doc = getattr(doc, "DO_Date", None)
|
||||||
date_str = date_doc.strftime('%Y-%m-%d') if date_doc else 'None'
|
date_str = date_doc.strftime("%Y-%m-%d") if date_doc else "None"
|
||||||
logger.info(f" DO_Date: {date_str}")
|
logger.info(f" DO_Date: {date_str}")
|
||||||
|
|
||||||
date_livr = getattr(doc, 'DO_DateLivr', None)
|
date_livr = getattr(doc, "DO_DateLivr", None)
|
||||||
date_livr_str = date_livr.strftime('%Y-%m-%d') if date_livr else 'None'
|
date_livr_str = date_livr.strftime("%Y-%m-%d") if date_livr else "None"
|
||||||
logger.info(f" DO_DateLivr: {date_livr_str}")
|
logger.info(f" DO_DateLivr: {date_livr_str}")
|
||||||
|
|
||||||
logger.info(f" DO_TotalHT: {getattr(doc, 'DO_TotalHT', 0)}€")
|
logger.info(f" DO_TotalHT: {getattr(doc, 'DO_TotalHT', 0)}€")
|
||||||
|
|
@ -40,7 +42,7 @@ def _compter_lignes_document(doc) -> int:
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
factory_lignes = doc.FactoryDocumentLigne
|
factory_lignes = doc.FactoryDocumentLigne
|
||||||
except:
|
except Exception:
|
||||||
factory_lignes = doc.FactoryDocumentVenteLigne
|
factory_lignes = doc.FactoryDocumentVenteLigne
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
|
|
@ -52,7 +54,7 @@ def _compter_lignes_document(doc) -> int:
|
||||||
break
|
break
|
||||||
count += 1
|
count += 1
|
||||||
index += 1
|
index += 1
|
||||||
except:
|
except Exception:
|
||||||
break
|
break
|
||||||
return count
|
return count
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -82,7 +84,7 @@ def _rechercher_devis_par_numero(numero: str, factory):
|
||||||
return persist_test
|
return persist_test
|
||||||
|
|
||||||
index += 1
|
index += 1
|
||||||
except:
|
except Exception:
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
logger.error(f" Devis {numero} non trouvé dans la liste")
|
logger.error(f" Devis {numero} non trouvé dans la liste")
|
||||||
|
|
@ -91,7 +93,6 @@ def _rechercher_devis_par_numero(numero: str, factory):
|
||||||
|
|
||||||
def _lire_document_sql(cursor, numero: str, type_doc: int):
|
def _lire_document_sql(cursor, numero: str, type_doc: int):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
query = """
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
d.DO_Piece, d.DO_Date, d.DO_Ref, d.DO_TotalHT, d.DO_TotalTTC,
|
d.DO_Piece, d.DO_Date, d.DO_Ref, d.DO_TotalHT, d.DO_TotalTTC,
|
||||||
|
|
@ -126,71 +127,56 @@ def _lire_document_sql(cursor, numero: str, type_doc: int):
|
||||||
numero_piece = _safe_strip(row[0])
|
numero_piece = _safe_strip(row[0])
|
||||||
logger.info(f"[SQL READ] Document trouvé: {numero_piece}")
|
logger.info(f"[SQL READ] Document trouvé: {numero_piece}")
|
||||||
|
|
||||||
|
|
||||||
doc = {
|
doc = {
|
||||||
"numero": numero_piece,
|
"numero": numero_piece,
|
||||||
"reference": _safe_strip(row[2]), # DO_Ref
|
"reference": _safe_strip(row[2]),
|
||||||
"date": str(row[1]) if row[1] else "", # DO_Date
|
"date": str(row[1]) if row[1] else "",
|
||||||
"date_livraison": (str(row[7]) if row[7] else ""), # DO_DateLivr
|
"date_livraison": (str(row[7]) if row[7] else ""),
|
||||||
"date_expedition": (
|
"date_expedition": (str(row[8]) if row[8] else ""),
|
||||||
str(row[8]) if row[8] else ""
|
"client_code": _safe_strip(row[6]),
|
||||||
), # DO_DateExpedition
|
"client_intitule": _safe_strip(row[39]),
|
||||||
"client_code": _safe_strip(row[6]), # DO_Tiers
|
"client_adresse": _safe_strip(row[40]),
|
||||||
"client_intitule": _safe_strip(row[39]), # CT_Intitule
|
"client_code_postal": _safe_strip(row[41]),
|
||||||
"client_adresse": _safe_strip(row[40]), # CT_Adresse
|
"client_ville": _safe_strip(row[42]),
|
||||||
"client_code_postal": _safe_strip(row[41]), # CT_CodePostal
|
"client_telephone": _safe_strip(row[43]),
|
||||||
"client_ville": _safe_strip(row[42]), # CT_Ville
|
"client_email": _safe_strip(row[44]),
|
||||||
"client_telephone": _safe_strip(row[43]), # CT_Telephone
|
"contact": _safe_strip(row[9]),
|
||||||
"client_email": _safe_strip(row[44]), # CT_EMail
|
"total_ht": float(row[3]) if row[3] else 0.0,
|
||||||
"contact": _safe_strip(row[9]), # DO_Contact
|
"total_ht_net": float(row[10]) if row[10] else 0.0,
|
||||||
"total_ht": float(row[3]) if row[3] else 0.0, # DO_TotalHT
|
"total_ttc": float(row[4]) if row[4] else 0.0,
|
||||||
"total_ht_net": float(row[10]) if row[10] else 0.0, # DO_TotalHTNet
|
"net_a_payer": float(row[11]) if row[11] else 0.0,
|
||||||
"total_ttc": float(row[4]) if row[4] else 0.0, # DO_TotalTTC
|
"montant_regle": (float(row[12]) if row[12] else 0.0),
|
||||||
"net_a_payer": float(row[11]) if row[11] else 0.0, # DO_NetAPayer
|
"reliquat": float(row[13]) if row[13] else 0.0,
|
||||||
"montant_regle": (
|
"taux_escompte": (float(row[14]) if row[14] else 0.0),
|
||||||
float(row[12]) if row[12] else 0.0
|
"escompte": float(row[15]) if row[15] else 0.0,
|
||||||
), # DO_MontantRegle
|
"taxe1": float(row[16]) if row[16] else 0.0,
|
||||||
"reliquat": float(row[13]) if row[13] else 0.0, # DO_Reliquat
|
"taxe2": float(row[17]) if row[17] else 0.0,
|
||||||
"taux_escompte": (
|
"taxe3": float(row[18]) if row[18] else 0.0,
|
||||||
float(row[14]) if row[14] else 0.0
|
"code_taxe1": _safe_strip(row[19]),
|
||||||
), # DO_TxEscompte
|
"code_taxe2": _safe_strip(row[20]),
|
||||||
"escompte": float(row[15]) if row[15] else 0.0, # DO_Escompte
|
"code_taxe3": _safe_strip(row[21]),
|
||||||
"taxe1": float(row[16]) if row[16] else 0.0, # DO_Taxe1
|
"statut": int(row[5]) if row[5] is not None else 0,
|
||||||
"taxe2": float(row[17]) if row[17] else 0.0, # DO_Taxe2
|
|
||||||
"taxe3": float(row[18]) if row[18] else 0.0, # DO_Taxe3
|
|
||||||
"code_taxe1": _safe_strip(row[19]), # DO_CodeTaxe1
|
|
||||||
"code_taxe2": _safe_strip(row[20]), # DO_CodeTaxe2
|
|
||||||
"code_taxe3": _safe_strip(row[21]), # DO_CodeTaxe3
|
|
||||||
"statut": int(row[5]) if row[5] is not None else 0, # DO_Statut
|
|
||||||
"statut_estatut": (
|
"statut_estatut": (
|
||||||
int(row[22]) if row[22] is not None else 0
|
int(row[22]) if row[22] is not None else 0
|
||||||
), # DO_EStatut
|
),
|
||||||
"imprime": int(row[23]) if row[23] is not None else 0, # DO_Imprim
|
"imprime": int(row[23]) if row[23] is not None else 0,
|
||||||
"valide": int(row[24]) if row[24] is not None else 0, # DO_Valide
|
"valide": int(row[24]) if row[24] is not None else 0,
|
||||||
"cloture": int(row[25]) if row[25] is not None else 0, # DO_Cloture
|
"cloture": int(row[25]) if row[25] is not None else 0,
|
||||||
"transfere": (
|
"transfere": (int(row[26]) if row[26] is not None else 0),
|
||||||
int(row[26]) if row[26] is not None else 0
|
"souche": int(row[27]) if row[27] is not None else 0,
|
||||||
), # DO_Transfere
|
"piece_origine": _safe_strip(row[28]),
|
||||||
"souche": int(row[27]) if row[27] is not None else 0, # DO_Souche
|
"guid": _safe_strip(row[29]),
|
||||||
"piece_origine": _safe_strip(row[28]), # DO_PieceOrig
|
"ca_num": _safe_strip(row[30]),
|
||||||
"guid": _safe_strip(row[29]), # DO_GUID
|
"cg_num": _safe_strip(row[31]),
|
||||||
"ca_num": _safe_strip(row[30]), # CA_Num
|
"expedition": (int(row[32]) if row[32] is not None else 1),
|
||||||
"cg_num": _safe_strip(row[31]), # CG_Num
|
"condition": (int(row[33]) if row[33] is not None else 1),
|
||||||
"expedition": (
|
"tarif": int(row[34]) if row[34] is not None else 1,
|
||||||
int(row[32]) if row[32] is not None else 1
|
"type_frais": (int(row[35]) if row[35] is not None else 0),
|
||||||
), # DO_Expedit
|
"valeur_frais": float(row[36]) if row[36] else 0.0,
|
||||||
"condition": (
|
|
||||||
int(row[33]) if row[33] is not None else 1
|
|
||||||
), # DO_Condition
|
|
||||||
"tarif": int(row[34]) if row[34] is not None else 1, # DO_Tarif
|
|
||||||
"type_frais": (
|
|
||||||
int(row[35]) if row[35] is not None else 0
|
|
||||||
), # DO_TypeFrais
|
|
||||||
"valeur_frais": float(row[36]) if row[36] else 0.0, # DO_ValFrais
|
|
||||||
"type_franco": (
|
"type_franco": (
|
||||||
int(row[37]) if row[37] is not None else 0
|
int(row[37]) if row[37] is not None else 0
|
||||||
), # DO_TypeFranco
|
),
|
||||||
"valeur_franco": float(row[38]) if row[38] else 0.0, # DO_ValFranco
|
"valeur_franco": float(row[38]) if row[38] else 0.0,
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
|
|
@ -216,8 +202,7 @@ def _lire_document_sql(cursor, numero: str, type_doc: int):
|
||||||
)
|
)
|
||||||
montant_net = (
|
montant_net = (
|
||||||
float(ligne_row.DL_MontantNet)
|
float(ligne_row.DL_MontantNet)
|
||||||
if hasattr(ligne_row, "DL_MontantNet")
|
if hasattr(ligne_row, "DL_MontantNet") and ligne_row.DL_MontantNet
|
||||||
and ligne_row.DL_MontantNet
|
|
||||||
else montant_ht
|
else montant_ht
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -245,15 +230,11 @@ def _lire_document_sql(cursor, numero: str, type_doc: int):
|
||||||
montant_taxe3 = montant_net * (taux_taxe3 / 100)
|
montant_taxe3 = montant_net * (taux_taxe3 / 100)
|
||||||
|
|
||||||
ligne = {
|
ligne = {
|
||||||
"numero_ligne": (
|
"numero_ligne": (int(ligne_row.DL_Ligne) if ligne_row.DL_Ligne else 0),
|
||||||
int(ligne_row.DL_Ligne) if ligne_row.DL_Ligne else 0
|
|
||||||
),
|
|
||||||
"article_code": _safe_strip(ligne_row.AR_Ref),
|
"article_code": _safe_strip(ligne_row.AR_Ref),
|
||||||
"designation": _safe_strip(ligne_row.DL_Design),
|
"designation": _safe_strip(ligne_row.DL_Design),
|
||||||
"designation_article": _safe_strip(ligne_row.AR_Design),
|
"designation_article": _safe_strip(ligne_row.AR_Design),
|
||||||
"quantite": (
|
"quantite": (float(ligne_row.DL_Qte) if ligne_row.DL_Qte else 0.0),
|
||||||
float(ligne_row.DL_Qte) if ligne_row.DL_Qte else 0.0
|
|
||||||
),
|
|
||||||
"quantite_livree": (
|
"quantite_livree": (
|
||||||
float(ligne_row.DL_QteLiv)
|
float(ligne_row.DL_QteLiv)
|
||||||
if hasattr(ligne_row, "DL_QteLiv") and ligne_row.DL_QteLiv
|
if hasattr(ligne_row, "DL_QteLiv") and ligne_row.DL_QteLiv
|
||||||
|
|
@ -311,9 +292,7 @@ def _lire_document_sql(cursor, numero: str, type_doc: int):
|
||||||
else 0
|
else 0
|
||||||
),
|
),
|
||||||
"remise_article": (
|
"remise_article": (
|
||||||
float(ligne_row.AR_Escompte)
|
float(ligne_row.AR_Escompte) if ligne_row.AR_Escompte else 0.0
|
||||||
if ligne_row.AR_Escompte
|
|
||||||
else 0.0
|
|
||||||
),
|
),
|
||||||
"taux_taxe1": taux_taxe1,
|
"taux_taxe1": taux_taxe1,
|
||||||
"montant_taxe1": montant_taxe1,
|
"montant_taxe1": montant_taxe1,
|
||||||
|
|
@ -333,20 +312,15 @@ def _lire_document_sql(cursor, numero: str, type_doc: int):
|
||||||
float(ligne_row.AR_CoutStd) if ligne_row.AR_CoutStd else 0.0
|
float(ligne_row.AR_CoutStd) if ligne_row.AR_CoutStd else 0.0
|
||||||
),
|
),
|
||||||
"poids_net": (
|
"poids_net": (
|
||||||
float(ligne_row.AR_PoidsNet)
|
float(ligne_row.AR_PoidsNet) if ligne_row.AR_PoidsNet else 0.0
|
||||||
if ligne_row.AR_PoidsNet
|
|
||||||
else 0.0
|
|
||||||
),
|
),
|
||||||
"poids_brut": (
|
"poids_brut": (
|
||||||
float(ligne_row.AR_PoidsBrut)
|
float(ligne_row.AR_PoidsBrut) if ligne_row.AR_PoidsBrut else 0.0
|
||||||
if ligne_row.AR_PoidsBrut
|
|
||||||
else 0.0
|
|
||||||
),
|
),
|
||||||
"unite_vente": _safe_strip(ligne_row.AR_UniteVen),
|
"unite_vente": _safe_strip(ligne_row.AR_UniteVen),
|
||||||
"date_livraison_ligne": (
|
"date_livraison_ligne": (
|
||||||
str(ligne_row.DL_DateLivr)
|
str(ligne_row.DL_DateLivr)
|
||||||
if hasattr(ligne_row, "DL_DateLivr")
|
if hasattr(ligne_row, "DL_DateLivr") and ligne_row.DL_DateLivr
|
||||||
and ligne_row.DL_DateLivr
|
|
||||||
else ""
|
else ""
|
||||||
),
|
),
|
||||||
"statut_ligne": (
|
"statut_ligne": (
|
||||||
|
|
@ -356,9 +330,7 @@ def _lire_document_sql(cursor, numero: str, type_doc: int):
|
||||||
else 0
|
else 0
|
||||||
),
|
),
|
||||||
"depot": (
|
"depot": (
|
||||||
_safe_strip(ligne_row.DE_No)
|
_safe_strip(ligne_row.DE_No) if hasattr(ligne_row, "DE_No") else ""
|
||||||
if hasattr(ligne_row, "DE_No")
|
|
||||||
else ""
|
|
||||||
),
|
),
|
||||||
"numero_commande": (
|
"numero_commande": (
|
||||||
_safe_strip(ligne_row.DL_NoColis)
|
_safe_strip(ligne_row.DL_NoColis)
|
||||||
|
|
@ -376,9 +348,9 @@ def _lire_document_sql(cursor, numero: str, type_doc: int):
|
||||||
doc["lignes"] = lignes
|
doc["lignes"] = lignes
|
||||||
doc["nb_lignes"] = len(lignes)
|
doc["nb_lignes"] = len(lignes)
|
||||||
|
|
||||||
total_ht_calcule = sum(l.get("montant_ligne_ht", 0) for l in lignes)
|
total_ht_calcule = sum(ligne.get("montant_ligne_ht", 0) for ligne in lignes)
|
||||||
total_ttc_calcule = sum(l.get("montant_ligne_ttc", 0) for l in lignes)
|
total_ttc_calcule = sum(ligne.get("montant_ligne_ttc", 0) for ligne in lignes)
|
||||||
total_taxes_calcule = sum(l.get("total_taxes", 0) for l in lignes)
|
total_taxes_calcule = sum(ligne.get("total_taxes", 0) for ligne in lignes)
|
||||||
|
|
||||||
doc["total_ht_calcule"] = total_ht_calcule
|
doc["total_ht_calcule"] = total_ht_calcule
|
||||||
doc["total_ttc_calcule"] = total_ttc_calcule
|
doc["total_ttc_calcule"] = total_ttc_calcule
|
||||||
|
|
@ -390,6 +362,7 @@ def _lire_document_sql(cursor, numero: str, type_doc: int):
|
||||||
logger.error(f" Erreur SQL lecture document {numero}: {e}", exc_info=True)
|
logger.error(f" Erreur SQL lecture document {numero}: {e}", exc_info=True)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _lister_documents_avec_lignes_sql(
|
def _lister_documents_avec_lignes_sql(
|
||||||
cursor,
|
cursor,
|
||||||
type_doc: int,
|
type_doc: int,
|
||||||
|
|
@ -423,7 +396,9 @@ def _lister_documents_avec_lignes_sql(
|
||||||
params = [type_doc_sql]
|
params = [type_doc_sql]
|
||||||
|
|
||||||
if filtre:
|
if filtre:
|
||||||
query += " AND (d.DO_Piece LIKE ? OR c.CT_Intitule LIKE ? OR d.DO_Ref LIKE ?)"
|
query += (
|
||||||
|
" AND (d.DO_Piece LIKE ? OR c.CT_Intitule LIKE ? OR d.DO_Ref LIKE ?)"
|
||||||
|
)
|
||||||
params.extend([f"%{filtre}%", f"%{filtre}%", f"%{filtre}%"])
|
params.extend([f"%{filtre}%", f"%{filtre}%", f"%{filtre}%"])
|
||||||
|
|
||||||
query += " ORDER BY d.DO_Date DESC"
|
query += " ORDER BY d.DO_Date DESC"
|
||||||
|
|
@ -469,9 +444,7 @@ def _lister_documents_avec_lignes_sql(
|
||||||
numero.upper().startswith(p) for p in prefixes_acceptes
|
numero.upper().startswith(p) for p in prefixes_acceptes
|
||||||
)
|
)
|
||||||
if not est_vente:
|
if not est_vente:
|
||||||
logger.info(
|
logger.info(f"[SQL LIST] {numero} : exclu (préfixe achat)")
|
||||||
f"[SQL LIST] {numero} : exclu (préfixe achat)"
|
|
||||||
)
|
|
||||||
stats["exclus_prefixe"] += 1
|
stats["exclus_prefixe"] += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -488,9 +461,7 @@ def _lister_documents_avec_lignes_sql(
|
||||||
"reference": _safe_strip(entete.DO_Ref),
|
"reference": _safe_strip(entete.DO_Ref),
|
||||||
"date": str(entete.DO_Date) if entete.DO_Date else "",
|
"date": str(entete.DO_Date) if entete.DO_Date else "",
|
||||||
"date_livraison": (
|
"date_livraison": (
|
||||||
str(entete.DO_DateLivr)
|
str(entete.DO_DateLivr) if entete.DO_DateLivr else ""
|
||||||
if entete.DO_DateLivr
|
|
||||||
else ""
|
|
||||||
),
|
),
|
||||||
"date_expedition": (
|
"date_expedition": (
|
||||||
str(entete.DO_DateExpedition)
|
str(entete.DO_DateExpedition)
|
||||||
|
|
@ -500,34 +471,22 @@ def _lister_documents_avec_lignes_sql(
|
||||||
"client_code": _safe_strip(entete.DO_Tiers),
|
"client_code": _safe_strip(entete.DO_Tiers),
|
||||||
"client_intitule": _safe_strip(entete.CT_Intitule),
|
"client_intitule": _safe_strip(entete.CT_Intitule),
|
||||||
"client_adresse": _safe_strip(entete.CT_Adresse),
|
"client_adresse": _safe_strip(entete.CT_Adresse),
|
||||||
"client_code_postal": _safe_strip(
|
"client_code_postal": _safe_strip(entete.CT_CodePostal),
|
||||||
entete.CT_CodePostal
|
|
||||||
),
|
|
||||||
"client_ville": _safe_strip(entete.CT_Ville),
|
"client_ville": _safe_strip(entete.CT_Ville),
|
||||||
"client_telephone": _safe_strip(
|
"client_telephone": _safe_strip(entete.CT_Telephone),
|
||||||
entete.CT_Telephone
|
|
||||||
),
|
|
||||||
"client_email": _safe_strip(entete.CT_EMail),
|
"client_email": _safe_strip(entete.CT_EMail),
|
||||||
"contact": _safe_strip(entete.DO_Contact),
|
"contact": _safe_strip(entete.DO_Contact),
|
||||||
"total_ht": (
|
"total_ht": (
|
||||||
float(entete.DO_TotalHT)
|
float(entete.DO_TotalHT) if entete.DO_TotalHT else 0.0
|
||||||
if entete.DO_TotalHT
|
|
||||||
else 0.0
|
|
||||||
),
|
),
|
||||||
"total_ht_net": (
|
"total_ht_net": (
|
||||||
float(entete.DO_TotalHTNet)
|
float(entete.DO_TotalHTNet) if entete.DO_TotalHTNet else 0.0
|
||||||
if entete.DO_TotalHTNet
|
|
||||||
else 0.0
|
|
||||||
),
|
),
|
||||||
"total_ttc": (
|
"total_ttc": (
|
||||||
float(entete.DO_TotalTTC)
|
float(entete.DO_TotalTTC) if entete.DO_TotalTTC else 0.0
|
||||||
if entete.DO_TotalTTC
|
|
||||||
else 0.0
|
|
||||||
),
|
),
|
||||||
"net_a_payer": (
|
"net_a_payer": (
|
||||||
float(entete.DO_NetAPayer)
|
float(entete.DO_NetAPayer) if entete.DO_NetAPayer else 0.0
|
||||||
if entete.DO_NetAPayer
|
|
||||||
else 0.0
|
|
||||||
),
|
),
|
||||||
"montant_regle": (
|
"montant_regle": (
|
||||||
float(entete.DO_MontantRegle)
|
float(entete.DO_MontantRegle)
|
||||||
|
|
@ -535,36 +494,22 @@ def _lister_documents_avec_lignes_sql(
|
||||||
else 0.0
|
else 0.0
|
||||||
),
|
),
|
||||||
"reliquat": (
|
"reliquat": (
|
||||||
float(entete.DO_Reliquat)
|
float(entete.DO_Reliquat) if entete.DO_Reliquat else 0.0
|
||||||
if entete.DO_Reliquat
|
|
||||||
else 0.0
|
|
||||||
),
|
),
|
||||||
"taux_escompte": (
|
"taux_escompte": (
|
||||||
float(entete.DO_TxEscompte)
|
float(entete.DO_TxEscompte) if entete.DO_TxEscompte else 0.0
|
||||||
if entete.DO_TxEscompte
|
|
||||||
else 0.0
|
|
||||||
),
|
),
|
||||||
"escompte": (
|
"escompte": (
|
||||||
float(entete.DO_Escompte)
|
float(entete.DO_Escompte) if entete.DO_Escompte else 0.0
|
||||||
if entete.DO_Escompte
|
|
||||||
else 0.0
|
|
||||||
),
|
|
||||||
"taxe1": (
|
|
||||||
float(entete.DO_Taxe1) if entete.DO_Taxe1 else 0.0
|
|
||||||
),
|
|
||||||
"taxe2": (
|
|
||||||
float(entete.DO_Taxe2) if entete.DO_Taxe2 else 0.0
|
|
||||||
),
|
|
||||||
"taxe3": (
|
|
||||||
float(entete.DO_Taxe3) if entete.DO_Taxe3 else 0.0
|
|
||||||
),
|
),
|
||||||
|
"taxe1": (float(entete.DO_Taxe1) if entete.DO_Taxe1 else 0.0),
|
||||||
|
"taxe2": (float(entete.DO_Taxe2) if entete.DO_Taxe2 else 0.0),
|
||||||
|
"taxe3": (float(entete.DO_Taxe3) if entete.DO_Taxe3 else 0.0),
|
||||||
"code_taxe1": _safe_strip(entete.DO_CodeTaxe1),
|
"code_taxe1": _safe_strip(entete.DO_CodeTaxe1),
|
||||||
"code_taxe2": _safe_strip(entete.DO_CodeTaxe2),
|
"code_taxe2": _safe_strip(entete.DO_CodeTaxe2),
|
||||||
"code_taxe3": _safe_strip(entete.DO_CodeTaxe3),
|
"code_taxe3": _safe_strip(entete.DO_CodeTaxe3),
|
||||||
"statut": (
|
"statut": (
|
||||||
int(entete.DO_Statut)
|
int(entete.DO_Statut) if entete.DO_Statut is not None else 0
|
||||||
if entete.DO_Statut is not None
|
|
||||||
else 0
|
|
||||||
),
|
),
|
||||||
"statut_estatut": (
|
"statut_estatut": (
|
||||||
int(entete.DO_EStatut)
|
int(entete.DO_EStatut)
|
||||||
|
|
@ -572,14 +517,10 @@ def _lister_documents_avec_lignes_sql(
|
||||||
else 0
|
else 0
|
||||||
),
|
),
|
||||||
"imprime": (
|
"imprime": (
|
||||||
int(entete.DO_Imprim)
|
int(entete.DO_Imprim) if entete.DO_Imprim is not None else 0
|
||||||
if entete.DO_Imprim is not None
|
|
||||||
else 0
|
|
||||||
),
|
),
|
||||||
"valide": (
|
"valide": (
|
||||||
int(entete.DO_Valide)
|
int(entete.DO_Valide) if entete.DO_Valide is not None else 0
|
||||||
if entete.DO_Valide is not None
|
|
||||||
else 0
|
|
||||||
),
|
),
|
||||||
"cloture": (
|
"cloture": (
|
||||||
int(entete.DO_Cloture)
|
int(entete.DO_Cloture)
|
||||||
|
|
@ -605,9 +546,7 @@ def _lister_documents_avec_lignes_sql(
|
||||||
else 0
|
else 0
|
||||||
),
|
),
|
||||||
"valeur_frais": (
|
"valeur_frais": (
|
||||||
float(entete.DO_ValFrais)
|
float(entete.DO_ValFrais) if entete.DO_ValFrais else 0.0
|
||||||
if entete.DO_ValFrais
|
|
||||||
else 0.0
|
|
||||||
),
|
),
|
||||||
"type_franco": (
|
"type_franco": (
|
||||||
int(entete.DO_TypeFranco)
|
int(entete.DO_TypeFranco)
|
||||||
|
|
@ -615,16 +554,12 @@ def _lister_documents_avec_lignes_sql(
|
||||||
else 0
|
else 0
|
||||||
),
|
),
|
||||||
"valeur_franco": (
|
"valeur_franco": (
|
||||||
float(entete.DO_ValFranco)
|
float(entete.DO_ValFranco) if entete.DO_ValFranco else 0.0
|
||||||
if entete.DO_ValFranco
|
|
||||||
else 0.0
|
|
||||||
),
|
),
|
||||||
"lignes": [],
|
"lignes": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(f"[SQL LIST] {numero} : document de base créé")
|
||||||
f"[SQL LIST] {numero} : document de base créé"
|
|
||||||
)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.error(
|
||||||
|
|
@ -665,20 +600,17 @@ def _lister_documents_avec_lignes_sql(
|
||||||
|
|
||||||
taux_taxe1 = (
|
taux_taxe1 = (
|
||||||
float(ligne_row.DL_Taxe1)
|
float(ligne_row.DL_Taxe1)
|
||||||
if hasattr(ligne_row, "DL_Taxe1")
|
if hasattr(ligne_row, "DL_Taxe1") and ligne_row.DL_Taxe1
|
||||||
and ligne_row.DL_Taxe1
|
|
||||||
else 0.0
|
else 0.0
|
||||||
)
|
)
|
||||||
taux_taxe2 = (
|
taux_taxe2 = (
|
||||||
float(ligne_row.DL_Taxe2)
|
float(ligne_row.DL_Taxe2)
|
||||||
if hasattr(ligne_row, "DL_Taxe2")
|
if hasattr(ligne_row, "DL_Taxe2") and ligne_row.DL_Taxe2
|
||||||
and ligne_row.DL_Taxe2
|
|
||||||
else 0.0
|
else 0.0
|
||||||
)
|
)
|
||||||
taux_taxe3 = (
|
taux_taxe3 = (
|
||||||
float(ligne_row.DL_Taxe3)
|
float(ligne_row.DL_Taxe3)
|
||||||
if hasattr(ligne_row, "DL_Taxe3")
|
if hasattr(ligne_row, "DL_Taxe3") and ligne_row.DL_Taxe3
|
||||||
and ligne_row.DL_Taxe3
|
|
||||||
else 0.0
|
else 0.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -691,21 +623,13 @@ def _lister_documents_avec_lignes_sql(
|
||||||
|
|
||||||
ligne = {
|
ligne = {
|
||||||
"numero_ligne": (
|
"numero_ligne": (
|
||||||
int(ligne_row.DL_Ligne)
|
int(ligne_row.DL_Ligne) if ligne_row.DL_Ligne else 0
|
||||||
if ligne_row.DL_Ligne
|
|
||||||
else 0
|
|
||||||
),
|
),
|
||||||
"article_code": _safe_strip(ligne_row.AR_Ref),
|
"article_code": _safe_strip(ligne_row.AR_Ref),
|
||||||
"designation": _safe_strip(
|
"designation": _safe_strip(ligne_row.DL_Design),
|
||||||
ligne_row.DL_Design
|
"designation_article": _safe_strip(ligne_row.AR_Design),
|
||||||
),
|
|
||||||
"designation_article": _safe_strip(
|
|
||||||
ligne_row.AR_Design
|
|
||||||
),
|
|
||||||
"quantite": (
|
"quantite": (
|
||||||
float(ligne_row.DL_Qte)
|
float(ligne_row.DL_Qte) if ligne_row.DL_Qte else 0.0
|
||||||
if ligne_row.DL_Qte
|
|
||||||
else 0.0
|
|
||||||
),
|
),
|
||||||
"quantite_livree": (
|
"quantite_livree": (
|
||||||
float(ligne_row.DL_QteLiv)
|
float(ligne_row.DL_QteLiv)
|
||||||
|
|
@ -785,18 +709,12 @@ def _lister_documents_avec_lignes_sql(
|
||||||
"total_taxes": montant_taxe1
|
"total_taxes": montant_taxe1
|
||||||
+ montant_taxe2
|
+ montant_taxe2
|
||||||
+ montant_taxe3,
|
+ montant_taxe3,
|
||||||
"famille_article": _safe_strip(
|
"famille_article": _safe_strip(ligne_row.FA_CodeFamille),
|
||||||
ligne_row.FA_CodeFamille
|
|
||||||
),
|
|
||||||
"gamme1": _safe_strip(ligne_row.AR_Gamme1),
|
"gamme1": _safe_strip(ligne_row.AR_Gamme1),
|
||||||
"gamme2": _safe_strip(ligne_row.AR_Gamme2),
|
"gamme2": _safe_strip(ligne_row.AR_Gamme2),
|
||||||
"code_barre": _safe_strip(
|
"code_barre": _safe_strip(ligne_row.AR_CodeBarre),
|
||||||
ligne_row.AR_CodeBarre
|
|
||||||
),
|
|
||||||
"type_article": _safe_strip(ligne_row.AR_Type),
|
"type_article": _safe_strip(ligne_row.AR_Type),
|
||||||
"nature_article": _safe_strip(
|
"nature_article": _safe_strip(ligne_row.AR_Nature),
|
||||||
ligne_row.AR_Nature
|
|
||||||
),
|
|
||||||
"garantie": _safe_strip(ligne_row.AR_Garantie),
|
"garantie": _safe_strip(ligne_row.AR_Garantie),
|
||||||
"cout_standard": (
|
"cout_standard": (
|
||||||
float(ligne_row.AR_CoutStd)
|
float(ligne_row.AR_CoutStd)
|
||||||
|
|
@ -813,9 +731,7 @@ def _lister_documents_avec_lignes_sql(
|
||||||
if ligne_row.AR_PoidsBrut
|
if ligne_row.AR_PoidsBrut
|
||||||
else 0.0
|
else 0.0
|
||||||
),
|
),
|
||||||
"unite_vente": _safe_strip(
|
"unite_vente": _safe_strip(ligne_row.AR_UniteVen),
|
||||||
ligne_row.AR_UniteVen
|
|
||||||
),
|
|
||||||
"date_livraison_ligne": (
|
"date_livraison_ligne": (
|
||||||
str(ligne_row.DL_DateLivr)
|
str(ligne_row.DL_DateLivr)
|
||||||
if hasattr(ligne_row, "DL_DateLivr")
|
if hasattr(ligne_row, "DL_DateLivr")
|
||||||
|
|
@ -848,13 +764,13 @@ def _lister_documents_avec_lignes_sql(
|
||||||
|
|
||||||
doc["nb_lignes"] = len(doc["lignes"])
|
doc["nb_lignes"] = len(doc["lignes"])
|
||||||
doc["total_ht_calcule"] = sum(
|
doc["total_ht_calcule"] = sum(
|
||||||
l.get("montant_ligne_ht", 0) for l in doc["lignes"]
|
ligne.get("montant_ligne_ht", 0) for ligne in doc["lignes"]
|
||||||
)
|
)
|
||||||
doc["total_ttc_calcule"] = sum(
|
doc["total_ttc_calcule"] = sum(
|
||||||
l.get("montant_ligne_ttc", 0) for l in doc["lignes"]
|
ligne.get("montant_ligne_ttc", 0) for ligne in doc["lignes"]
|
||||||
)
|
)
|
||||||
doc["total_taxes_calcule"] = sum(
|
doc["total_taxes_calcule"] = sum(
|
||||||
l.get("total_taxes", 0) for l in doc["lignes"]
|
ligne.get("total_taxes", 0) for ligne in doc["lignes"]
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
|
@ -881,13 +797,11 @@ def _lister_documents_avec_lignes_sql(
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
logger.info(f"[SQL LIST] ═══════════════════════════")
|
logger.info("[SQL LIST] ═══════════════════════════")
|
||||||
logger.info(f"[SQL LIST] STATISTIQUES FINALES:")
|
logger.info("[SQL LIST] STATISTIQUES FINALES:")
|
||||||
logger.info(f"[SQL LIST] Total SQL: {stats['total']}")
|
logger.info(f"[SQL LIST] Total SQL: {stats['total']}")
|
||||||
logger.info(f"[SQL LIST] Exclus préfixe: {stats['exclus_prefixe']}")
|
logger.info(f"[SQL LIST] Exclus préfixe: {stats['exclus_prefixe']}")
|
||||||
logger.info(
|
logger.info(f"[SQL LIST] Erreur construction: {stats['erreur_construction']}")
|
||||||
f"[SQL LIST] Erreur construction: {stats['erreur_construction']}"
|
|
||||||
)
|
|
||||||
logger.info(f"[SQL LIST] Erreur lignes: {stats['erreur_lignes']}")
|
logger.info(f"[SQL LIST] Erreur lignes: {stats['erreur_lignes']}")
|
||||||
logger.info(
|
logger.info(
|
||||||
f"[SQL LIST] Erreur transformations: {stats['erreur_transformations']}"
|
f"[SQL LIST] Erreur transformations: {stats['erreur_transformations']}"
|
||||||
|
|
@ -895,7 +809,7 @@ def _lister_documents_avec_lignes_sql(
|
||||||
logger.info(f"[SQL LIST] Erreur liaisons: {stats['erreur_liaisons']}")
|
logger.info(f"[SQL LIST] Erreur liaisons: {stats['erreur_liaisons']}")
|
||||||
logger.info(f"[SQL LIST] SUCCÈS: {stats['succes']}")
|
logger.info(f"[SQL LIST] SUCCÈS: {stats['succes']}")
|
||||||
logger.info(f"[SQL LIST] Documents retournés: {len(documents)}")
|
logger.info(f"[SQL LIST] Documents retournés: {len(documents)}")
|
||||||
logger.info(f"[SQL LIST] ═══════════════════════════")
|
logger.info("[SQL LIST] ═══════════════════════════")
|
||||||
|
|
||||||
return documents
|
return documents
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@ import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _clean_str(value, max_len: int) -> str:
|
def _clean_str(value, max_len: int) -> str:
|
||||||
"""Nettoie et tronque une chaîne"""
|
"""Nettoie et tronque une chaîne"""
|
||||||
if value is None or str(value).lower() in ('none', 'null', ''):
|
if value is None or str(value).lower() in ("none", "null", ""):
|
||||||
return ""
|
return ""
|
||||||
return str(value)[:max_len].strip()
|
return str(value)[:max_len].strip()
|
||||||
|
|
||||||
|
|
@ -83,6 +84,7 @@ def _convertir_type_pour_sql(type_doc: int) -> int:
|
||||||
mapping = {0: 0, 10: 1, 20: 2, 30: 3, 40: 4, 50: 5, 60: 6}
|
mapping = {0: 0, 10: 1, 20: 2, 30: 3, 40: 4, 50: 5, 60: 6}
|
||||||
return mapping.get(type_doc, type_doc)
|
return mapping.get(type_doc, type_doc)
|
||||||
|
|
||||||
|
|
||||||
def _convertir_type_depuis_sql(type_sql: int) -> int:
|
def _convertir_type_depuis_sql(type_sql: int) -> int:
|
||||||
"""SQL → COM : 0, 1, 2, 3... → 0, 10, 20, 30..."""
|
"""SQL → COM : 0, 1, 2, 3... → 0, 10, 20, 30..."""
|
||||||
mapping = {0: 0, 1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
|
mapping = {0: 0, 1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
|
||||||
|
|
@ -96,16 +98,17 @@ def _normaliser_type_document(type_doc: int) -> int:
|
||||||
return type_doc
|
return type_doc
|
||||||
|
|
||||||
mapping_normalisation = {
|
mapping_normalisation = {
|
||||||
1: 10, # Commande
|
1: 10,
|
||||||
2: 20, # Préparation
|
2: 20,
|
||||||
3: 30, # BL
|
3: 30,
|
||||||
4: 40, # Retour
|
4: 40,
|
||||||
5: 50, # Avoir
|
5: 50,
|
||||||
6: 60, # Facture
|
6: 60,
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapping_normalisation.get(type_doc, type_doc)
|
return mapping_normalisation.get(type_doc, type_doc)
|
||||||
|
|
||||||
|
|
||||||
def normaliser_date(valeur):
|
def normaliser_date(valeur):
|
||||||
if isinstance(valeur, str):
|
if isinstance(valeur, str):
|
||||||
try:
|
try:
|
||||||
|
|
@ -122,6 +125,7 @@ def normaliser_date(valeur):
|
||||||
else:
|
else:
|
||||||
return datetime.now()
|
return datetime.now()
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"_clean_str",
|
"_clean_str",
|
||||||
"_safe_strip",
|
"_safe_strip",
|
||||||
|
|
@ -131,5 +135,5 @@ __all__ = [
|
||||||
"_normaliser_type_document",
|
"_normaliser_type_document",
|
||||||
"_convertir_type_depuis_sql",
|
"_convertir_type_depuis_sql",
|
||||||
"_convertir_type_pour_sql",
|
"_convertir_type_pour_sql",
|
||||||
"normaliser_date"
|
"normaliser_date",
|
||||||
]
|
]
|
||||||
|
|
@ -4,25 +4,30 @@ from utils.functions.functions import _safe_strip
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def _contact_to_dict(contact, numero_client=None, contact_numero=None, n_contact=None) -> Dict:
|
|
||||||
|
def _contact_to_dict(
|
||||||
|
contact, numero_client=None, contact_numero=None, n_contact=None
|
||||||
|
) -> Dict:
|
||||||
try:
|
try:
|
||||||
civilite_code = getattr(contact, "Civilite", None)
|
civilite_code = getattr(contact, "Civilite", None)
|
||||||
civilite_map = {0: "M.", 1: "Mme", 2: "Mlle", 3: "Société"}
|
civilite_map = {0: "M.", 1: "Mme", 2: "Mlle", 3: "Société"}
|
||||||
civilite = civilite_map.get(civilite_code) if civilite_code is not None else None
|
civilite = (
|
||||||
|
civilite_map.get(civilite_code) if civilite_code is not None else None
|
||||||
|
)
|
||||||
|
|
||||||
telephone = None
|
telephone = None
|
||||||
portable = None
|
portable = None
|
||||||
telecopie = None
|
telecopie = None
|
||||||
email = None
|
email = None
|
||||||
|
|
||||||
if hasattr(contact, 'Telecom'):
|
if hasattr(contact, "Telecom"):
|
||||||
try:
|
try:
|
||||||
telecom = contact.Telecom
|
telecom = contact.Telecom
|
||||||
telephone = _safe_strip(getattr(telecom, "Telephone", None))
|
telephone = _safe_strip(getattr(telecom, "Telephone", None))
|
||||||
portable = _safe_strip(getattr(telecom, "Portable", None))
|
portable = _safe_strip(getattr(telecom, "Portable", None))
|
||||||
telecopie = _safe_strip(getattr(telecom, "Telecopie", None))
|
telecopie = _safe_strip(getattr(telecom, "Telecopie", None))
|
||||||
email = _safe_strip(getattr(telecom, "EMail", None))
|
email = _safe_strip(getattr(telecom, "EMail", None))
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -46,6 +51,7 @@ def _contact_to_dict(contact, numero_client=None, contact_numero=None, n_contact
|
||||||
logger.warning(f"Erreur conversion contact: {e}")
|
logger.warning(f"Erreur conversion contact: {e}")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
def _row_to_contact_dict(row) -> Dict:
|
def _row_to_contact_dict(row) -> Dict:
|
||||||
"""Convertit une ligne SQL en dictionnaire contact"""
|
"""Convertit une ligne SQL en dictionnaire contact"""
|
||||||
civilite_code = row.CT_Civilite
|
civilite_code = row.CT_Civilite
|
||||||
|
|
@ -55,7 +61,9 @@ def _row_to_contact_dict(row) -> Dict:
|
||||||
"numero": _safe_strip(row.CT_Num),
|
"numero": _safe_strip(row.CT_Num),
|
||||||
"contact_numero": row.CT_No,
|
"contact_numero": row.CT_No,
|
||||||
"n_contact": row.N_Contact,
|
"n_contact": row.N_Contact,
|
||||||
"civilite": civilite_map.get(civilite_code) if civilite_code is not None else None,
|
"civilite": civilite_map.get(civilite_code)
|
||||||
|
if civilite_code is not None
|
||||||
|
else None,
|
||||||
"nom": _safe_strip(row.CT_Nom),
|
"nom": _safe_strip(row.CT_Nom),
|
||||||
"prenom": _safe_strip(row.CT_Prenom),
|
"prenom": _safe_strip(row.CT_Prenom),
|
||||||
"fonction": _safe_strip(row.CT_Fonction),
|
"fonction": _safe_strip(row.CT_Fonction),
|
||||||
|
|
@ -69,6 +77,7 @@ def _row_to_contact_dict(row) -> Dict:
|
||||||
"skype": _safe_strip(row.CT_Skype),
|
"skype": _safe_strip(row.CT_Skype),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _row_to_tiers_dict(row) -> Dict:
|
def _row_to_tiers_dict(row) -> Dict:
|
||||||
"""Convertit une ligne SQL en dictionnaire tiers (factorisation DRY)"""
|
"""Convertit une ligne SQL en dictionnaire tiers (factorisation DRY)"""
|
||||||
return {
|
return {
|
||||||
|
|
@ -81,7 +90,6 @@ def _row_to_tiers_dict(row) -> Dict:
|
||||||
"siret": _safe_strip(row.CT_Siret),
|
"siret": _safe_strip(row.CT_Siret),
|
||||||
"tva_intra": _safe_strip(row.CT_Identifiant),
|
"tva_intra": _safe_strip(row.CT_Identifiant),
|
||||||
"code_naf": _safe_strip(row.CT_Ape),
|
"code_naf": _safe_strip(row.CT_Ape),
|
||||||
|
|
||||||
"contact": _safe_strip(row.CT_Contact),
|
"contact": _safe_strip(row.CT_Contact),
|
||||||
"adresse": _safe_strip(row.CT_Adresse),
|
"adresse": _safe_strip(row.CT_Adresse),
|
||||||
"complement": _safe_strip(row.CT_Complement),
|
"complement": _safe_strip(row.CT_Complement),
|
||||||
|
|
@ -89,19 +97,16 @@ def _row_to_tiers_dict(row) -> Dict:
|
||||||
"ville": _safe_strip(row.CT_Ville),
|
"ville": _safe_strip(row.CT_Ville),
|
||||||
"region": _safe_strip(row.CT_CodeRegion),
|
"region": _safe_strip(row.CT_CodeRegion),
|
||||||
"pays": _safe_strip(row.CT_Pays),
|
"pays": _safe_strip(row.CT_Pays),
|
||||||
|
|
||||||
"telephone": _safe_strip(row.CT_Telephone),
|
"telephone": _safe_strip(row.CT_Telephone),
|
||||||
"telecopie": _safe_strip(row.CT_Telecopie),
|
"telecopie": _safe_strip(row.CT_Telecopie),
|
||||||
"email": _safe_strip(row.CT_EMail),
|
"email": _safe_strip(row.CT_EMail),
|
||||||
"site_web": _safe_strip(row.CT_Site),
|
"site_web": _safe_strip(row.CT_Site),
|
||||||
"facebook": _safe_strip(row.CT_Facebook),
|
"facebook": _safe_strip(row.CT_Facebook),
|
||||||
"linkedin": _safe_strip(row.CT_LinkedIn),
|
"linkedin": _safe_strip(row.CT_LinkedIn),
|
||||||
|
|
||||||
"taux01": row.CT_Taux01,
|
"taux01": row.CT_Taux01,
|
||||||
"taux02": row.CT_Taux02,
|
"taux02": row.CT_Taux02,
|
||||||
"taux03": row.CT_Taux03,
|
"taux03": row.CT_Taux03,
|
||||||
"taux04": row.CT_Taux04,
|
"taux04": row.CT_Taux04,
|
||||||
|
|
||||||
"statistique01": _safe_strip(row.CT_Statistique01),
|
"statistique01": _safe_strip(row.CT_Statistique01),
|
||||||
"statistique02": _safe_strip(row.CT_Statistique02),
|
"statistique02": _safe_strip(row.CT_Statistique02),
|
||||||
"statistique03": _safe_strip(row.CT_Statistique03),
|
"statistique03": _safe_strip(row.CT_Statistique03),
|
||||||
|
|
@ -112,12 +117,10 @@ def _row_to_tiers_dict(row) -> Dict:
|
||||||
"statistique08": _safe_strip(row.CT_Statistique08),
|
"statistique08": _safe_strip(row.CT_Statistique08),
|
||||||
"statistique09": _safe_strip(row.CT_Statistique09),
|
"statistique09": _safe_strip(row.CT_Statistique09),
|
||||||
"statistique10": _safe_strip(row.CT_Statistique10),
|
"statistique10": _safe_strip(row.CT_Statistique10),
|
||||||
|
|
||||||
"encours_autorise": row.CT_Encours,
|
"encours_autorise": row.CT_Encours,
|
||||||
"assurance_credit": row.CT_Assurance,
|
"assurance_credit": row.CT_Assurance,
|
||||||
"langue": row.CT_Langue,
|
"langue": row.CT_Langue,
|
||||||
"commercial_code": row.CO_No,
|
"commercial_code": row.CO_No,
|
||||||
|
|
||||||
"lettrage_auto": (row.CT_Lettrage == 1),
|
"lettrage_auto": (row.CT_Lettrage == 1),
|
||||||
"est_actif": (row.CT_Sommeil == 0),
|
"est_actif": (row.CT_Sommeil == 0),
|
||||||
"type_facture": row.CT_Facture,
|
"type_facture": row.CT_Facture,
|
||||||
|
|
@ -129,16 +132,12 @@ def _row_to_tiers_dict(row) -> Dict:
|
||||||
"exclure_relance": (row.CT_NotRappel == 1),
|
"exclure_relance": (row.CT_NotRappel == 1),
|
||||||
"exclure_penalites": (row.CT_NotPenal == 1),
|
"exclure_penalites": (row.CT_NotPenal == 1),
|
||||||
"bon_a_payer": row.CT_BonAPayer,
|
"bon_a_payer": row.CT_BonAPayer,
|
||||||
|
|
||||||
"priorite_livraison": row.CT_PrioriteLivr,
|
"priorite_livraison": row.CT_PrioriteLivr,
|
||||||
"livraison_partielle": row.CT_LivrPartielle,
|
"livraison_partielle": row.CT_LivrPartielle,
|
||||||
"delai_transport": row.CT_DelaiTransport,
|
"delai_transport": row.CT_DelaiTransport,
|
||||||
"delai_appro": row.CT_DelaiAppro,
|
"delai_appro": row.CT_DelaiAppro,
|
||||||
|
|
||||||
"commentaire": _safe_strip(row.CT_Commentaire),
|
"commentaire": _safe_strip(row.CT_Commentaire),
|
||||||
|
|
||||||
"section_analytique": _safe_strip(row.CA_Num),
|
"section_analytique": _safe_strip(row.CA_Num),
|
||||||
|
|
||||||
"mode_reglement_code": row.MR_No,
|
"mode_reglement_code": row.MR_No,
|
||||||
"surveillance_active": (row.CT_Surveillance == 1),
|
"surveillance_active": (row.CT_Surveillance == 1),
|
||||||
"coface": _safe_strip(row.CT_Coface),
|
"coface": _safe_strip(row.CT_Coface),
|
||||||
|
|
@ -149,12 +148,12 @@ def _row_to_tiers_dict(row) -> Dict:
|
||||||
"sv_objet_maj": _safe_strip(row.CT_SvObjetMaj),
|
"sv_objet_maj": _safe_strip(row.CT_SvObjetMaj),
|
||||||
"sv_chiffre_affaires": row.CT_SvCA,
|
"sv_chiffre_affaires": row.CT_SvCA,
|
||||||
"sv_resultat": row.CT_SvResultat,
|
"sv_resultat": row.CT_SvResultat,
|
||||||
|
|
||||||
"compte_general": _safe_strip(row.CG_NumPrinc),
|
"compte_general": _safe_strip(row.CG_NumPrinc),
|
||||||
"categorie_tarif": row.N_CatTarif,
|
"categorie_tarif": row.N_CatTarif,
|
||||||
"categorie_compta": row.N_CatCompta,
|
"categorie_compta": row.N_CatCompta,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"_contact_to_dict",
|
"_contact_to_dict",
|
||||||
"_row_to_contact_dict",
|
"_row_to_contact_dict",
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from utils.functions.functions import (
|
||||||
_convertir_type_depuis_sql,
|
_convertir_type_depuis_sql,
|
||||||
_convertir_type_pour_sql,
|
_convertir_type_pour_sql,
|
||||||
_normaliser_type_document,
|
_normaliser_type_document,
|
||||||
_get_type_libelle
|
_get_type_libelle,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
@ -24,6 +24,7 @@ def _verifier_devis_non_transforme(numero: str, doc, cursor):
|
||||||
if statut_actuel == 5:
|
if statut_actuel == 5:
|
||||||
raise ValueError(f" Devis {numero} déjà transformé (statut=5)")
|
raise ValueError(f" Devis {numero} déjà transformé (statut=5)")
|
||||||
|
|
||||||
|
|
||||||
def verifier_si_deja_transforme_sql(numero_source, cursor, type_source):
|
def verifier_si_deja_transforme_sql(numero_source, cursor, type_source):
|
||||||
"""Version corrigée avec normalisation des types"""
|
"""Version corrigée avec normalisation des types"""
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|
@ -57,7 +58,6 @@ def verifier_si_deja_transforme_sql(numero_source, cursor, type_source):
|
||||||
return {"deja_transforme": False, "documents_cibles": []}
|
return {"deja_transforme": False, "documents_cibles": []}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
query = f"""
|
query = f"""
|
||||||
SELECT DISTINCT
|
SELECT DISTINCT
|
||||||
dc.DO_Piece,
|
dc.DO_Piece,
|
||||||
|
|
@ -81,8 +81,8 @@ def verifier_si_deja_transforme_sql(numero_source, cursor, type_source):
|
||||||
|
|
||||||
doc = {
|
doc = {
|
||||||
"numero": row.DO_Piece.strip() if row.DO_Piece else "",
|
"numero": row.DO_Piece.strip() if row.DO_Piece else "",
|
||||||
"type": type_normalise, # ← TYPE NORMALISÉ
|
"type": type_normalise,
|
||||||
"type_brut": type_brut, # Garder aussi le type original
|
"type_brut": type_brut,
|
||||||
"type_libelle": _get_type_libelle(type_brut),
|
"type_libelle": _get_type_libelle(type_brut),
|
||||||
"statut": int(row.DO_Statut) if row.DO_Statut else 0,
|
"statut": int(row.DO_Statut) if row.DO_Statut else 0,
|
||||||
"nb_lignes": int(row.NbLignes) if row.NbLignes else 0,
|
"nb_lignes": int(row.NbLignes) if row.NbLignes else 0,
|
||||||
|
|
@ -101,9 +101,7 @@ def verifier_si_deja_transforme_sql(numero_source, cursor, type_source):
|
||||||
f"[VERIF] Document {numero_source} a {len(documents_cibles)} transformation(s)"
|
f"[VERIF] Document {numero_source} a {len(documents_cibles)} transformation(s)"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.info(
|
logger.info(f"[VERIF] Document {numero_source} pas encore transformé")
|
||||||
f"[VERIF] Document {numero_source} pas encore transformé"
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"deja_transforme": deja_transforme,
|
"deja_transforme": deja_transforme,
|
||||||
|
|
@ -114,21 +112,19 @@ def verifier_si_deja_transforme_sql(numero_source, cursor, type_source):
|
||||||
logger.error(f"[VERIF] Erreur vérification: {e}")
|
logger.error(f"[VERIF] Erreur vérification: {e}")
|
||||||
return {"deja_transforme": False, "documents_cibles": []}
|
return {"deja_transforme": False, "documents_cibles": []}
|
||||||
|
|
||||||
|
|
||||||
def peut_etre_transforme(cursor, numero_source, type_source, type_cible):
|
def peut_etre_transforme(cursor, numero_source, type_source, type_cible):
|
||||||
"""Version corrigée avec normalisation"""
|
"""Version corrigée avec normalisation"""
|
||||||
type_source = _normaliser_type_document(type_source)
|
type_source = _normaliser_type_document(type_source)
|
||||||
type_cible = _normaliser_type_document(type_cible)
|
type_cible = _normaliser_type_document(type_cible)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"[VERIF_TRANSFO] {numero_source} "
|
f"[VERIF_TRANSFO] {numero_source} (type {type_source}) → type {type_cible}"
|
||||||
f"(type {type_source}) → type {type_cible}"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
verif = verifier_si_deja_transforme_sql(cursor, numero_source, type_source)
|
verif = verifier_si_deja_transforme_sql(cursor, numero_source, type_source)
|
||||||
|
|
||||||
docs_meme_type = [
|
docs_meme_type = [d for d in verif["documents_cibles"] if d["type"] == type_cible]
|
||||||
d for d in verif["documents_cibles"] if d["type"] == type_cible
|
|
||||||
]
|
|
||||||
|
|
||||||
if docs_meme_type:
|
if docs_meme_type:
|
||||||
nums = [d["numero"] for d in docs_meme_type]
|
nums = [d["numero"] for d in docs_meme_type]
|
||||||
|
|
@ -145,6 +141,7 @@ def peut_etre_transforme(cursor, numero_source, type_source, type_cible):
|
||||||
"documents_existants": [],
|
"documents_existants": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def lire_erreurs_sage(obj, nom_obj=""):
|
def lire_erreurs_sage(obj, nom_obj=""):
|
||||||
erreurs = []
|
erreurs = []
|
||||||
try:
|
try:
|
||||||
|
|
@ -154,7 +151,7 @@ def lire_erreurs_sage(obj, nom_obj=""):
|
||||||
nb_erreurs = 0
|
nb_erreurs = 0
|
||||||
try:
|
try:
|
||||||
nb_erreurs = obj.Errors.Count
|
nb_erreurs = obj.Errors.Count
|
||||||
except:
|
except Exception:
|
||||||
return erreurs
|
return erreurs
|
||||||
|
|
||||||
if nb_erreurs == 0:
|
if nb_erreurs == 0:
|
||||||
|
|
@ -165,13 +162,13 @@ def lire_erreurs_sage(obj, nom_obj=""):
|
||||||
err = None
|
err = None
|
||||||
try:
|
try:
|
||||||
err = obj.Errors.Item(i)
|
err = obj.Errors.Item(i)
|
||||||
except:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
err = obj.Errors(i)
|
err = obj.Errors(i)
|
||||||
except:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
err = obj.Errors.Item(i - 1)
|
err = obj.Errors.Item(i - 1)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if err is not None:
|
if err is not None:
|
||||||
|
|
@ -185,7 +182,7 @@ def lire_erreurs_sage(obj, nom_obj=""):
|
||||||
if val:
|
if val:
|
||||||
description = str(val)
|
description = str(val)
|
||||||
break
|
break
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for attr in ["Field", "FieldName", "Champ", "Property"]:
|
for attr in ["Field", "FieldName", "Champ", "Property"]:
|
||||||
|
|
@ -194,7 +191,7 @@ def lire_erreurs_sage(obj, nom_obj=""):
|
||||||
if val:
|
if val:
|
||||||
field = str(val)
|
field = str(val)
|
||||||
break
|
break
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for attr in ["Number", "Code", "ErrorCode", "Numero"]:
|
for attr in ["Number", "Code", "ErrorCode", "Numero"]:
|
||||||
|
|
@ -203,7 +200,7 @@ def lire_erreurs_sage(obj, nom_obj=""):
|
||||||
if val is not None:
|
if val is not None:
|
||||||
number = str(val)
|
number = str(val)
|
||||||
break
|
break
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if description or field or number:
|
if description or field or number:
|
||||||
|
|
@ -226,9 +223,10 @@ def lire_erreurs_sage(obj, nom_obj=""):
|
||||||
|
|
||||||
return erreurs
|
return erreurs
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"_verifier_devis_non_transforme",
|
"_verifier_devis_non_transforme",
|
||||||
"verifier_si_deja_transforme_sql",
|
"verifier_si_deja_transforme_sql",
|
||||||
"peut_etre_transforme",
|
"peut_etre_transforme",
|
||||||
"lire_erreurs_sage"
|
"lire_erreurs_sage",
|
||||||
]
|
]
|
||||||
|
|
@ -3,6 +3,7 @@ import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _cast_client(persist_obj):
|
def _cast_client(persist_obj):
|
||||||
try:
|
try:
|
||||||
obj = win32com.client.CastTo(persist_obj, "IBOClient3")
|
obj = win32com.client.CastTo(persist_obj, "IBOClient3")
|
||||||
|
|
@ -12,6 +13,7 @@ def _cast_client(persist_obj):
|
||||||
logger.debug(f" _cast_client échoue: {e}")
|
logger.debug(f" _cast_client échoue: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _extraire_client(client_obj):
|
def _extraire_client(client_obj):
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
|
|
@ -40,23 +42,23 @@ def _extraire_client(client_obj):
|
||||||
qualite_code = getattr(client_obj, "CT_Type", None)
|
qualite_code = getattr(client_obj, "CT_Type", None)
|
||||||
|
|
||||||
qualite_map = {
|
qualite_map = {
|
||||||
0: "CLI", # Client
|
0: "CLI",
|
||||||
1: "FOU", # Fournisseur
|
1: "FOU",
|
||||||
2: "CLIFOU", # Client + Fournisseur
|
2: "CLIFOU",
|
||||||
3: "SAL", # Salarié
|
3: "SAL",
|
||||||
4: "PRO", # Prospect
|
4: "PRO",
|
||||||
}
|
}
|
||||||
|
|
||||||
data["qualite"] = qualite_map.get(qualite_code, "CLI")
|
data["qualite"] = qualite_map.get(qualite_code, "CLI")
|
||||||
data["est_fournisseur"] = qualite_code in [1, 2]
|
data["est_fournisseur"] = qualite_code in [1, 2]
|
||||||
|
|
||||||
except:
|
except Exception:
|
||||||
data["qualite"] = "CLI"
|
data["qualite"] = "CLI"
|
||||||
data["est_fournisseur"] = False
|
data["est_fournisseur"] = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["est_prospect"] = getattr(client_obj, "CT_Prospect", 0) == 1
|
data["est_prospect"] = getattr(client_obj, "CT_Prospect", 0) == 1
|
||||||
except:
|
except Exception:
|
||||||
data["est_prospect"] = False
|
data["est_prospect"] = False
|
||||||
|
|
||||||
if data["est_prospect"]:
|
if data["est_prospect"]:
|
||||||
|
|
@ -72,7 +74,7 @@ def _extraire_client(client_obj):
|
||||||
sommeil = getattr(client_obj, "CT_Sommeil", 0)
|
sommeil = getattr(client_obj, "CT_Sommeil", 0)
|
||||||
data["est_actif"] = sommeil == 0
|
data["est_actif"] = sommeil == 0
|
||||||
data["est_en_sommeil"] = sommeil == 1
|
data["est_en_sommeil"] = sommeil == 1
|
||||||
except:
|
except Exception:
|
||||||
data["est_actif"] = True
|
data["est_actif"] = True
|
||||||
data["est_en_sommeil"] = False
|
data["est_en_sommeil"] = False
|
||||||
|
|
||||||
|
|
@ -81,24 +83,24 @@ def _extraire_client(client_obj):
|
||||||
data["forme_juridique"] = forme_juridique
|
data["forme_juridique"] = forme_juridique
|
||||||
data["est_entreprise"] = bool(forme_juridique)
|
data["est_entreprise"] = bool(forme_juridique)
|
||||||
data["est_particulier"] = not bool(forme_juridique)
|
data["est_particulier"] = not bool(forme_juridique)
|
||||||
except:
|
except Exception:
|
||||||
data["forme_juridique"] = ""
|
data["forme_juridique"] = ""
|
||||||
data["est_entreprise"] = False
|
data["est_entreprise"] = False
|
||||||
data["est_particulier"] = True
|
data["est_particulier"] = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["civilite"] = getattr(client_obj, "CT_Civilite", "").strip()
|
data["civilite"] = getattr(client_obj, "CT_Civilite", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["civilite"] = ""
|
data["civilite"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["nom"] = getattr(client_obj, "CT_Nom", "").strip()
|
data["nom"] = getattr(client_obj, "CT_Nom", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["nom"] = ""
|
data["nom"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["prenom"] = getattr(client_obj, "CT_Prenom", "").strip()
|
data["prenom"] = getattr(client_obj, "CT_Prenom", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["prenom"] = ""
|
data["prenom"] = ""
|
||||||
|
|
||||||
if data.get("nom") or data.get("prenom"):
|
if data.get("nom") or data.get("prenom"):
|
||||||
|
|
@ -115,7 +117,7 @@ def _extraire_client(client_obj):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["contact"] = getattr(client_obj, "CT_Contact", "").strip()
|
data["contact"] = getattr(client_obj, "CT_Contact", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["contact"] = ""
|
data["contact"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -123,36 +125,32 @@ def _extraire_client(client_obj):
|
||||||
if adresse_obj:
|
if adresse_obj:
|
||||||
try:
|
try:
|
||||||
data["adresse"] = getattr(adresse_obj, "Adresse", "").strip()
|
data["adresse"] = getattr(adresse_obj, "Adresse", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["adresse"] = ""
|
data["adresse"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["complement"] = getattr(
|
data["complement"] = getattr(adresse_obj, "Complement", "").strip()
|
||||||
adresse_obj, "Complement", ""
|
except Exception:
|
||||||
).strip()
|
|
||||||
except:
|
|
||||||
data["complement"] = ""
|
data["complement"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["code_postal"] = getattr(
|
data["code_postal"] = getattr(adresse_obj, "CodePostal", "").strip()
|
||||||
adresse_obj, "CodePostal", ""
|
except Exception:
|
||||||
).strip()
|
|
||||||
except:
|
|
||||||
data["code_postal"] = ""
|
data["code_postal"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["ville"] = getattr(adresse_obj, "Ville", "").strip()
|
data["ville"] = getattr(adresse_obj, "Ville", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["ville"] = ""
|
data["ville"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["region"] = getattr(adresse_obj, "Region", "").strip()
|
data["region"] = getattr(adresse_obj, "Region", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["region"] = ""
|
data["region"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["pays"] = getattr(adresse_obj, "Pays", "").strip()
|
data["pays"] = getattr(adresse_obj, "Pays", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["pays"] = ""
|
data["pays"] = ""
|
||||||
else:
|
else:
|
||||||
data["adresse"] = ""
|
data["adresse"] = ""
|
||||||
|
|
@ -175,22 +173,22 @@ def _extraire_client(client_obj):
|
||||||
if telecom:
|
if telecom:
|
||||||
try:
|
try:
|
||||||
data["telephone"] = getattr(telecom, "Telephone", "").strip()
|
data["telephone"] = getattr(telecom, "Telephone", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["telephone"] = ""
|
data["telephone"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["portable"] = getattr(telecom, "Portable", "").strip()
|
data["portable"] = getattr(telecom, "Portable", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["portable"] = ""
|
data["portable"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["telecopie"] = getattr(telecom, "Telecopie", "").strip()
|
data["telecopie"] = getattr(telecom, "Telecopie", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["telecopie"] = ""
|
data["telecopie"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["email"] = getattr(telecom, "EMail", "").strip()
|
data["email"] = getattr(telecom, "EMail", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["email"] = ""
|
data["email"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -200,7 +198,7 @@ def _extraire_client(client_obj):
|
||||||
or getattr(telecom, "SiteWeb", "")
|
or getattr(telecom, "SiteWeb", "")
|
||||||
)
|
)
|
||||||
data["site_web"] = str(site).strip() if site else ""
|
data["site_web"] = str(site).strip() if site else ""
|
||||||
except:
|
except Exception:
|
||||||
data["site_web"] = ""
|
data["site_web"] = ""
|
||||||
else:
|
else:
|
||||||
data["telephone"] = ""
|
data["telephone"] = ""
|
||||||
|
|
@ -218,17 +216,17 @@ def _extraire_client(client_obj):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["siret"] = getattr(client_obj, "CT_Siret", "").strip()
|
data["siret"] = getattr(client_obj, "CT_Siret", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["siret"] = ""
|
data["siret"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["siren"] = getattr(client_obj, "CT_Siren", "").strip()
|
data["siren"] = getattr(client_obj, "CT_Siren", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["siren"] = ""
|
data["siren"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["tva_intra"] = getattr(client_obj, "CT_Identifiant", "").strip()
|
data["tva_intra"] = getattr(client_obj, "CT_Identifiant", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["tva_intra"] = ""
|
data["tva_intra"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -236,34 +234,34 @@ def _extraire_client(client_obj):
|
||||||
getattr(client_obj, "CT_CodeNAF", "").strip()
|
getattr(client_obj, "CT_CodeNAF", "").strip()
|
||||||
or getattr(client_obj, "CT_APE", "").strip()
|
or getattr(client_obj, "CT_APE", "").strip()
|
||||||
)
|
)
|
||||||
except:
|
except Exception:
|
||||||
data["code_naf"] = ""
|
data["code_naf"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["secteur"] = getattr(client_obj, "CT_Secteur", "").strip()
|
data["secteur"] = getattr(client_obj, "CT_Secteur", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["secteur"] = ""
|
data["secteur"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
effectif = getattr(client_obj, "CT_Effectif", None)
|
effectif = getattr(client_obj, "CT_Effectif", None)
|
||||||
data["effectif"] = int(effectif) if effectif is not None else None
|
data["effectif"] = int(effectif) if effectif is not None else None
|
||||||
except:
|
except Exception:
|
||||||
data["effectif"] = None
|
data["effectif"] = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ca = getattr(client_obj, "CT_ChiffreAffaire", None)
|
ca = getattr(client_obj, "CT_ChiffreAffaire", None)
|
||||||
data["ca_annuel"] = float(ca) if ca is not None else None
|
data["ca_annuel"] = float(ca) if ca is not None else None
|
||||||
except:
|
except Exception:
|
||||||
data["ca_annuel"] = None
|
data["ca_annuel"] = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["commercial_code"] = getattr(client_obj, "CO_No", "").strip()
|
data["commercial_code"] = getattr(client_obj, "CO_No", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
data["commercial_code"] = getattr(
|
data["commercial_code"] = getattr(
|
||||||
client_obj, "CT_Commercial", ""
|
client_obj, "CT_Commercial", ""
|
||||||
).strip()
|
).strip()
|
||||||
except:
|
except Exception:
|
||||||
data["commercial_code"] = ""
|
data["commercial_code"] = ""
|
||||||
|
|
||||||
if data.get("commercial_code"):
|
if data.get("commercial_code"):
|
||||||
|
|
@ -276,48 +274,46 @@ def _extraire_client(client_obj):
|
||||||
).strip()
|
).strip()
|
||||||
else:
|
else:
|
||||||
data["commercial_nom"] = ""
|
data["commercial_nom"] = ""
|
||||||
except:
|
except Exception:
|
||||||
data["commercial_nom"] = ""
|
data["commercial_nom"] = ""
|
||||||
else:
|
else:
|
||||||
data["commercial_nom"] = ""
|
data["commercial_nom"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["categorie_tarifaire"] = getattr(client_obj, "N_CatTarif", None)
|
data["categorie_tarifaire"] = getattr(client_obj, "N_CatTarif", None)
|
||||||
except:
|
except Exception:
|
||||||
data["categorie_tarifaire"] = None
|
data["categorie_tarifaire"] = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["categorie_comptable"] = getattr(client_obj, "N_CatCompta", None)
|
data["categorie_comptable"] = getattr(client_obj, "N_CatCompta", None)
|
||||||
except:
|
except Exception:
|
||||||
data["categorie_comptable"] = None
|
data["categorie_comptable"] = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["encours_autorise"] = float(getattr(client_obj, "CT_Encours", 0.0))
|
data["encours_autorise"] = float(getattr(client_obj, "CT_Encours", 0.0))
|
||||||
except:
|
except Exception:
|
||||||
data["encours_autorise"] = 0.0
|
data["encours_autorise"] = 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["assurance_credit"] = float(
|
data["assurance_credit"] = float(getattr(client_obj, "CT_Assurance", 0.0))
|
||||||
getattr(client_obj, "CT_Assurance", 0.0)
|
except Exception:
|
||||||
)
|
|
||||||
except:
|
|
||||||
data["assurance_credit"] = 0.0
|
data["assurance_credit"] = 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["compte_general"] = getattr(client_obj, "CG_Num", "").strip()
|
data["compte_general"] = getattr(client_obj, "CG_Num", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["compte_general"] = ""
|
data["compte_general"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
date_creation = getattr(client_obj, "CT_DateCreate", None)
|
date_creation = getattr(client_obj, "CT_DateCreate", None)
|
||||||
data["date_creation"] = str(date_creation) if date_creation else ""
|
data["date_creation"] = str(date_creation) if date_creation else ""
|
||||||
except:
|
except Exception:
|
||||||
data["date_creation"] = ""
|
data["date_creation"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
date_modif = getattr(client_obj, "CT_DateModif", None)
|
date_modif = getattr(client_obj, "CT_DateModif", None)
|
||||||
data["date_modification"] = str(date_modif) if date_modif else ""
|
data["date_modification"] = str(date_modif) if date_modif else ""
|
||||||
except:
|
except Exception:
|
||||||
data["date_modification"] = ""
|
data["date_modification"] = ""
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
@ -326,7 +322,5 @@ def _extraire_client(client_obj):
|
||||||
logger.error(f" ERREUR GLOBALE _extraire_client: {e}", exc_info=True)
|
logger.error(f" ERREUR GLOBALE _extraire_client: {e}", exc_info=True)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
__all__ = [
|
|
||||||
"_extraire_client",
|
__all__ = ["_extraire_client", "_cast_client"]
|
||||||
"_cast_client"
|
|
||||||
]
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
|
|
||||||
import win32com.client
|
import win32com.client
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _extraire_fournisseur_enrichi(fourn_obj):
|
def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
try:
|
try:
|
||||||
numero = getattr(fourn_obj, "CT_Num", "").strip()
|
numero = getattr(fourn_obj, "CT_Num", "").strip()
|
||||||
|
|
@ -15,7 +15,7 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
data = {
|
data = {
|
||||||
"numero": numero,
|
"numero": numero,
|
||||||
"intitule": intitule,
|
"intitule": intitule,
|
||||||
"type": 1, # Fournisseur
|
"type": 1,
|
||||||
"est_fournisseur": True,
|
"est_fournisseur": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,7 +23,7 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
sommeil = getattr(fourn_obj, "CT_Sommeil", 0)
|
sommeil = getattr(fourn_obj, "CT_Sommeil", 0)
|
||||||
data["est_actif"] = sommeil == 0
|
data["est_actif"] = sommeil == 0
|
||||||
data["en_sommeil"] = sommeil == 1
|
data["en_sommeil"] = sommeil == 1
|
||||||
except:
|
except Exception:
|
||||||
data["est_actif"] = True
|
data["est_actif"] = True
|
||||||
data["en_sommeil"] = False
|
data["en_sommeil"] = False
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
or getattr(telecom_obj, "SiteWeb", "")
|
or getattr(telecom_obj, "SiteWeb", "")
|
||||||
)
|
)
|
||||||
data["site_web"] = str(site).strip() if site else ""
|
data["site_web"] = str(site).strip() if site else ""
|
||||||
except:
|
except Exception:
|
||||||
data["site_web"] = ""
|
data["site_web"] = ""
|
||||||
else:
|
else:
|
||||||
data["telephone"] = ""
|
data["telephone"] = ""
|
||||||
|
|
@ -101,7 +101,7 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["siret"] = getattr(fourn_obj, "CT_Siret", "").strip()
|
data["siret"] = getattr(fourn_obj, "CT_Siret", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["siret"] = ""
|
data["siret"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -109,12 +109,12 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
data["siren"] = data["siret"][:9]
|
data["siren"] = data["siret"][:9]
|
||||||
else:
|
else:
|
||||||
data["siren"] = getattr(fourn_obj, "CT_Siren", "").strip()
|
data["siren"] = getattr(fourn_obj, "CT_Siren", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["siren"] = ""
|
data["siren"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["tva_intra"] = getattr(fourn_obj, "CT_Identifiant", "").strip()
|
data["tva_intra"] = getattr(fourn_obj, "CT_Identifiant", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["tva_intra"] = ""
|
data["tva_intra"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -122,14 +122,14 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
getattr(fourn_obj, "CT_CodeNAF", "").strip()
|
getattr(fourn_obj, "CT_CodeNAF", "").strip()
|
||||||
or getattr(fourn_obj, "CT_APE", "").strip()
|
or getattr(fourn_obj, "CT_APE", "").strip()
|
||||||
)
|
)
|
||||||
except:
|
except Exception:
|
||||||
data["code_naf"] = ""
|
data["code_naf"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["forme_juridique"] = getattr(
|
data["forme_juridique"] = getattr(
|
||||||
fourn_obj, "CT_FormeJuridique", ""
|
fourn_obj, "CT_FormeJuridique", ""
|
||||||
).strip()
|
).strip()
|
||||||
except:
|
except Exception:
|
||||||
data["forme_juridique"] = ""
|
data["forme_juridique"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -137,7 +137,7 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
data["categorie_tarifaire"] = (
|
data["categorie_tarifaire"] = (
|
||||||
int(cat_tarif) if cat_tarif is not None else None
|
int(cat_tarif) if cat_tarif is not None else None
|
||||||
)
|
)
|
||||||
except:
|
except Exception:
|
||||||
data["categorie_tarifaire"] = None
|
data["categorie_tarifaire"] = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -145,7 +145,7 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
data["categorie_comptable"] = (
|
data["categorie_comptable"] = (
|
||||||
int(cat_compta) if cat_compta is not None else None
|
int(cat_compta) if cat_compta is not None else None
|
||||||
)
|
)
|
||||||
except:
|
except Exception:
|
||||||
data["categorie_comptable"] = None
|
data["categorie_comptable"] = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -162,11 +162,11 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
).strip()
|
).strip()
|
||||||
else:
|
else:
|
||||||
data["conditions_reglement_libelle"] = ""
|
data["conditions_reglement_libelle"] = ""
|
||||||
except:
|
except Exception:
|
||||||
data["conditions_reglement_libelle"] = ""
|
data["conditions_reglement_libelle"] = ""
|
||||||
else:
|
else:
|
||||||
data["conditions_reglement_libelle"] = ""
|
data["conditions_reglement_libelle"] = ""
|
||||||
except:
|
except Exception:
|
||||||
data["conditions_reglement_code"] = ""
|
data["conditions_reglement_code"] = ""
|
||||||
data["conditions_reglement_libelle"] = ""
|
data["conditions_reglement_libelle"] = ""
|
||||||
|
|
||||||
|
|
@ -184,11 +184,11 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
).strip()
|
).strip()
|
||||||
else:
|
else:
|
||||||
data["mode_reglement_libelle"] = ""
|
data["mode_reglement_libelle"] = ""
|
||||||
except:
|
except Exception:
|
||||||
data["mode_reglement_libelle"] = ""
|
data["mode_reglement_libelle"] = ""
|
||||||
else:
|
else:
|
||||||
data["mode_reglement_libelle"] = ""
|
data["mode_reglement_libelle"] = ""
|
||||||
except:
|
except Exception:
|
||||||
data["mode_reglement_code"] = ""
|
data["mode_reglement_code"] = ""
|
||||||
data["mode_reglement_libelle"] = ""
|
data["mode_reglement_libelle"] = ""
|
||||||
|
|
||||||
|
|
@ -199,53 +199,36 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
|
|
||||||
if factory_banque:
|
if factory_banque:
|
||||||
index = 1
|
index = 1
|
||||||
while index <= 5: # Max 5 comptes bancaires
|
while index <= 5:
|
||||||
try:
|
try:
|
||||||
banque_persist = factory_banque.List(index)
|
banque_persist = factory_banque.List(index)
|
||||||
if banque_persist is None:
|
if banque_persist is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
banque = win32com.client.CastTo(
|
banque = win32com.client.CastTo(banque_persist, "IBOBanque3")
|
||||||
banque_persist, "IBOBanque3"
|
|
||||||
)
|
|
||||||
banque.Read()
|
banque.Read()
|
||||||
|
|
||||||
compte_bancaire = {
|
compte_bancaire = {
|
||||||
"banque_nom": getattr(
|
"banque_nom": getattr(banque, "BI_Intitule", "").strip(),
|
||||||
banque, "BI_Intitule", ""
|
|
||||||
).strip(),
|
|
||||||
"iban": getattr(banque, "RIB_Iban", "").strip(),
|
"iban": getattr(banque, "RIB_Iban", "").strip(),
|
||||||
"bic": getattr(banque, "RIB_Bic", "").strip(),
|
"bic": getattr(banque, "RIB_Bic", "").strip(),
|
||||||
"code_banque": getattr(
|
"code_banque": getattr(banque, "RIB_Banque", "").strip(),
|
||||||
banque, "RIB_Banque", ""
|
"code_guichet": getattr(banque, "RIB_Guichet", "").strip(),
|
||||||
).strip(),
|
"numero_compte": getattr(banque, "RIB_Compte", "").strip(),
|
||||||
"code_guichet": getattr(
|
|
||||||
banque, "RIB_Guichet", ""
|
|
||||||
).strip(),
|
|
||||||
"numero_compte": getattr(
|
|
||||||
banque, "RIB_Compte", ""
|
|
||||||
).strip(),
|
|
||||||
"cle_rib": getattr(banque, "RIB_Cle", "").strip(),
|
"cle_rib": getattr(banque, "RIB_Cle", "").strip(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if compte_bancaire["iban"] or compte_bancaire["numero_compte"]:
|
||||||
compte_bancaire["iban"]
|
|
||||||
or compte_bancaire["numero_compte"]
|
|
||||||
):
|
|
||||||
data["coordonnees_bancaires"].append(compte_bancaire)
|
data["coordonnees_bancaires"].append(compte_bancaire)
|
||||||
|
|
||||||
index += 1
|
index += 1
|
||||||
except:
|
except Exception:
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(
|
logger.debug(f"Erreur coordonnées bancaires fournisseur {numero}: {e}")
|
||||||
f"Erreur coordonnées bancaires fournisseur {numero}: {e}"
|
|
||||||
)
|
|
||||||
|
|
||||||
if data["coordonnees_bancaires"]:
|
if data["coordonnees_bancaires"]:
|
||||||
data["iban_principal"] = data["coordonnees_bancaires"][0].get(
|
data["iban_principal"] = data["coordonnees_bancaires"][0].get("iban", "")
|
||||||
"iban", ""
|
|
||||||
)
|
|
||||||
data["bic_principal"] = data["coordonnees_bancaires"][0].get("bic", "")
|
data["bic_principal"] = data["coordonnees_bancaires"][0].get("bic", "")
|
||||||
else:
|
else:
|
||||||
data["iban_principal"] = ""
|
data["iban_principal"] = ""
|
||||||
|
|
@ -258,15 +241,13 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
|
|
||||||
if factory_contact:
|
if factory_contact:
|
||||||
index = 1
|
index = 1
|
||||||
while index <= 20: # Max 20 contacts
|
while index <= 20:
|
||||||
try:
|
try:
|
||||||
contact_persist = factory_contact.List(index)
|
contact_persist = factory_contact.List(index)
|
||||||
if contact_persist is None:
|
if contact_persist is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
contact = win32com.client.CastTo(
|
contact = win32com.client.CastTo(contact_persist, "IBOContact3")
|
||||||
contact_persist, "IBOContact3"
|
|
||||||
)
|
|
||||||
contact.Read()
|
contact.Read()
|
||||||
|
|
||||||
contact_data = {
|
contact_data = {
|
||||||
|
|
@ -274,14 +255,14 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
"prenom": getattr(contact, "CO_Prenom", "").strip(),
|
"prenom": getattr(contact, "CO_Prenom", "").strip(),
|
||||||
"fonction": getattr(contact, "CO_Fonction", "").strip(),
|
"fonction": getattr(contact, "CO_Fonction", "").strip(),
|
||||||
"service": getattr(contact, "CO_Service", "").strip(),
|
"service": getattr(contact, "CO_Service", "").strip(),
|
||||||
"telephone": getattr(
|
"telephone": getattr(contact, "CO_Telephone", "").strip(),
|
||||||
contact, "CO_Telephone", ""
|
|
||||||
).strip(),
|
|
||||||
"portable": getattr(contact, "CO_Portable", "").strip(),
|
"portable": getattr(contact, "CO_Portable", "").strip(),
|
||||||
"email": getattr(contact, "CO_EMail", "").strip(),
|
"email": getattr(contact, "CO_EMail", "").strip(),
|
||||||
}
|
}
|
||||||
|
|
||||||
nom_complet = f"{contact_data['prenom']} {contact_data['nom']}".strip()
|
nom_complet = (
|
||||||
|
f"{contact_data['prenom']} {contact_data['nom']}".strip()
|
||||||
|
)
|
||||||
if nom_complet:
|
if nom_complet:
|
||||||
contact_data["nom_complet"] = nom_complet
|
contact_data["nom_complet"] = nom_complet
|
||||||
else:
|
else:
|
||||||
|
|
@ -291,7 +272,7 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
data["contacts"].append(contact_data)
|
data["contacts"].append(contact_data)
|
||||||
|
|
||||||
index += 1
|
index += 1
|
||||||
except:
|
except Exception:
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Erreur contacts fournisseur {numero}: {e}")
|
logger.debug(f"Erreur contacts fournisseur {numero}: {e}")
|
||||||
|
|
@ -305,29 +286,29 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["encours_autorise"] = float(getattr(fourn_obj, "CT_Encours", 0.0))
|
data["encours_autorise"] = float(getattr(fourn_obj, "CT_Encours", 0.0))
|
||||||
except:
|
except Exception:
|
||||||
data["encours_autorise"] = 0.0
|
data["encours_autorise"] = 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["ca_annuel"] = float(getattr(fourn_obj, "CT_ChiffreAffaire", 0.0))
|
data["ca_annuel"] = float(getattr(fourn_obj, "CT_ChiffreAffaire", 0.0))
|
||||||
except:
|
except Exception:
|
||||||
data["ca_annuel"] = 0.0
|
data["ca_annuel"] = 0.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data["compte_general"] = getattr(fourn_obj, "CG_Num", "").strip()
|
data["compte_general"] = getattr(fourn_obj, "CG_Num", "").strip()
|
||||||
except:
|
except Exception:
|
||||||
data["compte_general"] = ""
|
data["compte_general"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
date_creation = getattr(fourn_obj, "CT_DateCreate", None)
|
date_creation = getattr(fourn_obj, "CT_DateCreate", None)
|
||||||
data["date_creation"] = str(date_creation) if date_creation else ""
|
data["date_creation"] = str(date_creation) if date_creation else ""
|
||||||
except:
|
except Exception:
|
||||||
data["date_creation"] = ""
|
data["date_creation"] = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
date_modif = getattr(fourn_obj, "CT_DateModif", None)
|
date_modif = getattr(fourn_obj, "CT_DateModif", None)
|
||||||
data["date_modification"] = str(date_modif) if date_modif else ""
|
data["date_modification"] = str(date_modif) if date_modif else ""
|
||||||
except:
|
except Exception:
|
||||||
data["date_modification"] = ""
|
data["date_modification"] = ""
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
@ -378,6 +359,4 @@ def _extraire_fournisseur_enrichi(fourn_obj):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = ["_extraire_fournisseur_enrichi"]
|
||||||
"_extraire_fournisseur_enrichi"
|
|
||||||
]
|
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,6 @@ def _build_tiers_select_query() -> str:
|
||||||
-- COMPTE GENERAL ET CATEGORIES (3)
|
-- COMPTE GENERAL ET CATEGORIES (3)
|
||||||
CG_NumPrinc, N_CatTarif, N_CatCompta
|
CG_NumPrinc, N_CatTarif, N_CatCompta
|
||||||
"""
|
"""
|
||||||
__all__ = [
|
|
||||||
"_build_tiers_select_query"
|
|
||||||
]
|
__all__ = ["_build_tiers_select_query"]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue