refactor(utils): move normaliser_type_doc to generic_functions module

This commit is contained in:
Fanilo-Nantenaina 2026-01-06 00:07:58 +03:00
parent 19811a2290
commit a08fb12b56
3 changed files with 15 additions and 14 deletions

12
api.py
View file

@ -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:

View file

@ -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:

View file

@ -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"]