diff --git a/api.py b/api.py index c37cbde..b4448e2 100644 --- a/api.py +++ b/api.py @@ -90,6 +90,7 @@ from core.sage_context import ( ) from utils.generic_functions import ( _preparer_lignes_document, + normaliser_type_doc, universign_envoyer, universign_statut, ) @@ -924,17 +925,6 @@ async def commande_vers_facture(id: str, session: AsyncSession = Depends(get_ses raise HTTPException(500, str(e)) -def normaliser_type_doc(type_doc: int) -> int: - TYPES_AUTORISES = {0, 10, 30, 50, 60} - - if type_doc not in TYPES_AUTORISES: - raise ValueError( - f"type_doc invalide ({type_doc}). Valeurs autorisées : {sorted(TYPES_AUTORISES)}" - ) - - return type_doc if type_doc == 0 else type_doc // 10 - - @app.get("/admin/signatures/relances-auto", tags=["Admin"]) async def relancer_signatures_automatique(session: AsyncSession = Depends(get_session)): try: diff --git a/routes/universign.py b/routes/universign.py index be9ee34..e468084 100644 --- a/routes/universign.py +++ b/routes/universign.py @@ -6,7 +6,6 @@ from typing import List, Optional from datetime import datetime from pydantic import BaseModel, EmailStr import logging -from api import normaliser_type_doc from email_queue import email_queue from database import get_session from database import ( @@ -18,6 +17,7 @@ from database import ( ) from services.universign_sync import UniversignSyncService from config.config import settings +from utils.generic_functions import normaliser_type_doc from utils.universign_status_mapping import get_status_message from database.models.email import EmailLog @@ -80,7 +80,7 @@ async def create_signature( ): try: pdf_bytes = email_queue._generate_pdf( - request.doc_id, normaliser_type_doc(request.type_doc) + request.sage_document_id, normaliser_type_doc(request.sage_document_type) ) if not pdf_bytes: diff --git a/utils/generic_functions.py b/utils/generic_functions.py index 94eb4f2..a628612 100644 --- a/utils/generic_functions.py +++ b/utils/generic_functions.py @@ -267,6 +267,17 @@ async def universign_statut(transaction_id: str) -> Dict: return {"statut": "ERREUR", "error": str(e)} +def normaliser_type_doc(type_doc: int) -> int: + TYPES_AUTORISES = {0, 10, 30, 50, 60} + + if type_doc not in TYPES_AUTORISES: + raise ValueError( + f"type_doc invalide ({type_doc}). Valeurs autorisées : {sorted(TYPES_AUTORISES)}" + ) + + return type_doc if type_doc == 0 else type_doc // 10 + + def _preparer_lignes_document(lignes: List) -> List[Dict]: return [ { @@ -547,4 +558,4 @@ def get_status_message(local_status: str, lang: str = "fr") -> str: return f"{icon} {message}" -__all__ = ["_preparer_lignes_document"] +__all__ = ["_preparer_lignes_document", "normaliser_type_doc"]