retrait des fonctions d'aide et finalisation de la génération de fichier pdf

conforme
This commit is contained in:
2026-03-16 21:21:07 +01:00
parent b403efd056
commit bb12b3777f
2 changed files with 7 additions and 18 deletions

View File

@@ -12,6 +12,7 @@ from config import settings
from auth import get_current_user
from template_helper import render
from generate_facturx_jinja2 import Address, Party, Invoice, InvoiceLine, generate_facturx_xml
from facturx import generate_from_binary
router = APIRouter(prefix="/factures", tags=["factures"], dependencies=[Depends(get_current_user)])
templates = Jinja2Templates(directory="templates")
@@ -158,23 +159,6 @@ def changer_statut_facture(
from generate_facturx_jinja2 import Invoice, Party, Address, InvoiceLine, filter_amount, filter_datefmt
@router.get("/{facture_id}/facturx")
def telecharger_facturx(request: Request, facture_id: int, db: Session = Depends(get_db)):
facture = get_invoice_data(facture_id, db) # votre appel BDD
# facture = db.query(Facture).get(facture_id)
if not facture:
raise HTTPException(status_code=404)
xml_bytes = generate_facturx_xml(facture)
filename=f"factur-x-{facture_id}.xml"
return Response(
content= xml_bytes,
media_type="application/xml",
headers={"Content-Disposition": f'attachment; filename="{filename}"'}
)
@router.get("/{facture_id}/pdf", response_class=HTMLResponse)
def telecharger_pdf(request: Request, facture_id: int, db: Session = Depends(get_db)):
@@ -192,6 +176,12 @@ def telecharger_pdf(request: Request, facture_id: int, db: Session = Depends(get
filename = f"facture-{facture.numero}.pdf"
xml_bytes = generate_facturx_xml(get_invoice_data(facture_id, db))
pdf_bytes = generate_from_binary(pdf_bytes, xml_bytes)
filename = f"facture-{facture.numero}.pdf"
return Response(
content=pdf_bytes,
media_type="application/pdf",