PDF conforme Factur-X #2

Open
jblb wants to merge 10 commits from jblb/BillManager:devel into master
2 changed files with 7 additions and 18 deletions
Showing only changes of commit bb12b3777f - Show all commits

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",

View File

@@ -29,7 +29,6 @@
<td>
<a href="/factures/{{ f.id }}" class="btn btn-sm">Voir</a>
<a href="/factures/{{ f.id }}/pdf" class="btn btn-sm btn-primary">PDF</a>
<a href="/factures/{{ f.id }}/facturx" class="btn btn-sm btn-primary">facturx</a>
</td>
</tr>
{% endfor %}