refactor(utils): move normaliser_type_doc to generic_functions module
This commit is contained in:
parent
19811a2290
commit
a08fb12b56
3 changed files with 15 additions and 14 deletions
12
api.py
12
api.py
|
|
@ -90,6 +90,7 @@ from core.sage_context import (
|
||||||
)
|
)
|
||||||
from utils.generic_functions import (
|
from utils.generic_functions import (
|
||||||
_preparer_lignes_document,
|
_preparer_lignes_document,
|
||||||
|
normaliser_type_doc,
|
||||||
universign_envoyer,
|
universign_envoyer,
|
||||||
universign_statut,
|
universign_statut,
|
||||||
)
|
)
|
||||||
|
|
@ -924,17 +925,6 @@ async def commande_vers_facture(id: str, session: AsyncSession = Depends(get_ses
|
||||||
raise HTTPException(500, str(e))
|
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"])
|
@app.get("/admin/signatures/relances-auto", tags=["Admin"])
|
||||||
async def relancer_signatures_automatique(session: AsyncSession = Depends(get_session)):
|
async def relancer_signatures_automatique(session: AsyncSession = Depends(get_session)):
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ from typing import List, Optional
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pydantic import BaseModel, EmailStr
|
from pydantic import BaseModel, EmailStr
|
||||||
import logging
|
import logging
|
||||||
from api import normaliser_type_doc
|
|
||||||
from email_queue import email_queue
|
from email_queue import email_queue
|
||||||
from database import get_session
|
from database import get_session
|
||||||
from database import (
|
from database import (
|
||||||
|
|
@ -18,6 +17,7 @@ from database import (
|
||||||
)
|
)
|
||||||
from services.universign_sync import UniversignSyncService
|
from services.universign_sync import UniversignSyncService
|
||||||
from config.config import settings
|
from config.config import settings
|
||||||
|
from utils.generic_functions import normaliser_type_doc
|
||||||
from utils.universign_status_mapping import get_status_message
|
from utils.universign_status_mapping import get_status_message
|
||||||
|
|
||||||
from database.models.email import EmailLog
|
from database.models.email import EmailLog
|
||||||
|
|
@ -80,7 +80,7 @@ async def create_signature(
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
pdf_bytes = email_queue._generate_pdf(
|
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:
|
if not pdf_bytes:
|
||||||
|
|
|
||||||
|
|
@ -267,6 +267,17 @@ async def universign_statut(transaction_id: str) -> Dict:
|
||||||
return {"statut": "ERREUR", "error": str(e)}
|
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]:
|
def _preparer_lignes_document(lignes: List) -> List[Dict]:
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|
@ -547,4 +558,4 @@ def get_status_message(local_status: str, lang: str = "fr") -> str:
|
||||||
return f"{icon} {message}"
|
return f"{icon} {message}"
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["_preparer_lignes_document"]
|
__all__ = ["_preparer_lignes_document", "normaliser_type_doc"]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue