fix(crm): servir el PDF de cotización por el backend (no exponer MinIO)
La URL prefirmada usaba el host interno http://minio:9000 (no accesible desde el navegador). Se agrega GET /quotes/{id}/pdf que devuelve el PDF por el backend (vía nginx) y el visor usa un blob autenticado (api.getBlob). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, Depends, File, Query, UploadFile, status
|
||||
from fastapi import APIRouter, Depends, File, Query, Response, UploadFile, status
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from core.database import get_core_db
|
||||
@@ -152,16 +152,23 @@ def reject_quote(
|
||||
return service.reject_quote(db, quote_id, current_user["tenant_id"], company_id)
|
||||
|
||||
|
||||
@router.get("/quotes/{quote_id}/pdf-url")
|
||||
def quote_pdf_url(
|
||||
@router.get("/quotes/{quote_id}/pdf")
|
||||
def quote_pdf(
|
||||
quote_id: int,
|
||||
company_id: int = Query(..., description="Company ID"),
|
||||
current_user: dict = Depends(get_current_user),
|
||||
db: Session = Depends(get_core_db),
|
||||
):
|
||||
"""Genera el PDF de la cotización (formato maestro + marca) y devuelve una URL."""
|
||||
url = pdf_service.get_pdf_url(db, quote_id, current_user["tenant_id"], company_id)
|
||||
return {"url": url}
|
||||
"""Devuelve el PDF de la cotización directamente (vía backend, sin exponer MinIO)."""
|
||||
tenant_id = current_user["tenant_id"]
|
||||
quote = service.get_quote(db, quote_id, tenant_id, company_id)
|
||||
pdf_bytes = pdf_service.build_pdf_bytes(db, quote, tenant_id, company_id)
|
||||
ref = (quote.reference or f"cot-{quote.id}").replace("/", "-")
|
||||
return Response(
|
||||
content=pdf_bytes,
|
||||
media_type="application/pdf",
|
||||
headers={"Content-Disposition": f'inline; filename="cotizacion-{ref}.pdf"'},
|
||||
)
|
||||
|
||||
|
||||
@router.post("/quotes/{quote_id}/send-email")
|
||||
|
||||
Reference in New Issue
Block a user