89 lines
2.5 KiB
Python
89 lines
2.5 KiB
Python
from pathlib import Path
|
|
import base64
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def get_societe_row(cursor):
|
|
"""Récupère la ligne P_DOSSIER"""
|
|
query = """
|
|
SELECT
|
|
D_RaisonSoc, D_NumDoss, D_Siret, D_Ape, D_Identifiant,
|
|
D_Adresse, D_Complement, D_CodePostal, D_Ville,
|
|
D_CodeRegion, D_Pays,
|
|
D_Telephone, D_Telecopie, D_EMail, D_EMailSoc, D_Site,
|
|
D_Capital, D_FormeJuridique,
|
|
D_DebutExo01, D_FinExo01,
|
|
D_DebutExo02, D_FinExo02,
|
|
D_DebutExo03, D_FinExo03,
|
|
D_DebutExo04, D_FinExo04,
|
|
D_DebutExo05, D_FinExo05,
|
|
N_DeviseCompte, N_DeviseEquival,
|
|
D_LgCg, D_LgAn,
|
|
D_RegimeFEC,
|
|
BM_Intitule,
|
|
cbMarq,
|
|
D_Logo
|
|
FROM P_DOSSIER
|
|
"""
|
|
|
|
cursor.execute(query)
|
|
return cursor.fetchone()
|
|
|
|
|
|
def build_exercices(row) -> list:
|
|
"""Construit la liste des exercices"""
|
|
exercices_data = [
|
|
(1, row.D_DebutExo01, row.D_FinExo01),
|
|
(2, row.D_DebutExo02, row.D_FinExo02),
|
|
(3, row.D_DebutExo03, row.D_FinExo03),
|
|
(4, row.D_DebutExo04, row.D_FinExo04),
|
|
(5, row.D_DebutExo05, row.D_FinExo05),
|
|
]
|
|
|
|
exercices = []
|
|
for numero, debut, fin in exercices_data:
|
|
if debut and debut.year > 1753:
|
|
exercices.append(
|
|
{
|
|
"numero": numero,
|
|
"debut": debut.isoformat(),
|
|
"fin": fin.isoformat() if fin and fin.year > 1753 else None,
|
|
}
|
|
)
|
|
|
|
return exercices
|
|
|
|
|
|
def add_logo(societe_dict: dict) -> None:
|
|
"""Ajoute le logo en base64 au dict"""
|
|
logo_path = societe_dict.pop("_logo_path", None)
|
|
|
|
if logo_path and Path(logo_path).exists():
|
|
try:
|
|
ext = Path(logo_path).suffix.lower()
|
|
content_type = {
|
|
".png": "image/png",
|
|
".jpg": "image/jpeg",
|
|
".jpeg": "image/jpeg",
|
|
".bmp": "image/bmp",
|
|
".gif": "image/gif",
|
|
}.get(ext, "image/png")
|
|
|
|
with open(logo_path, "rb") as f:
|
|
societe_dict["logo_base64"] = base64.b64encode(f.read()).decode("utf-8")
|
|
societe_dict["logo_content_type"] = content_type
|
|
return
|
|
except Exception as e:
|
|
logger.warning(f"Erreur conversion logo: {e}")
|
|
|
|
societe_dict["logo_base64"] = None
|
|
societe_dict["logo_content_type"] = None
|
|
|
|
|
|
__all__ = [
|
|
"get_societe_row",
|
|
"build_exercices",
|
|
"add_logo",
|
|
]
|