From 320f41c0ff3c71f2367b721da493518aa1c523b7 Mon Sep 17 00:00:00 2001 From: gitea Date: Thu, 27 Nov 2025 17:40:23 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Mejoras=20implementadas:=20?= =?UTF-8?q?=F0=9F=94=8D=20Mejor=20debugging:=20Logs=20detallados=20en=20co?= =?UTF-8?q?nsola=20para=20ver=20qu=C3=A9=20est=C3=A1=20pasando=20Muestra?= =?UTF-8?q?=20la=20URL=20del=20logo=20que=20intenta=20cargar=20Indica=20el?= =?UTF-8?q?=20c=C3=B3digo=20HTTP=20de=20respuesta=20Stack=20trace=20comple?= =?UTF-8?q?to=20si=20hay=20error=20=F0=9F=93=90=20Ajuste=20autom=C3=A1tico?= =?UTF-8?q?=20de=20tama=C3=B1o:=20Antes:=20Forzaba=2040mm=20x=2040mm=20(di?= =?UTF-8?q?storsionaba=20la=20imagen)=20Ahora:=20Mantiene=20proporciones?= =?UTF-8?q?=20(aspect=20ratio)=20Ancho=20m=C3=A1ximo:=2050mm=20Alto=20m?= =?UTF-8?q?=C3=A1ximo:=2040mm=20Se=20ajusta=20autom=C3=A1ticamente=20al=20?= =?UTF-8?q?que=20limite=20primero=20=E2=9C=85=20Validaciones=20adicionales?= =?UTF-8?q?:=20Verifica=20que=20el=20checklist=20exista=20Verifica=20que?= =?UTF-8?q?=20tenga=20logo=5Furl=20configurado=20Mensajes=20informativos?= =?UTF-8?q?=20en=20cada=20caso=20Backend=20v1.0.79?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/main.py | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/backend/app/main.py b/backend/app/main.py index fd5cbd4..6cd96ed 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -204,7 +204,7 @@ def send_completed_inspection_to_n8n(inspection, db): # No lanzamos excepción para no interrumpir el flujo normal -BACKEND_VERSION = "1.0.78" +BACKEND_VERSION = "1.0.79" app = FastAPI(title="Checklist Inteligente API", version=BACKEND_VERSION) # S3/MinIO configuration @@ -1405,20 +1405,49 @@ def generate_inspection_pdf(inspection_id: int, db: Session) -> str: elements.append(Spacer(1, 10*mm)) # Logo del checklist (si existe) - if checklist.logo_url: + if checklist and checklist.logo_url: try: + print(f"🔍 Intentando cargar logo desde: {checklist.logo_url}") logo_resp = requests.get(checklist.logo_url, timeout=10) + print(f"📡 Respuesta del servidor: {logo_resp.status_code}") + if logo_resp.status_code == 200: logo_bytes = BytesIO(logo_resp.content) - logo_img = RLImage(logo_bytes, width=40*mm, height=40*mm) - logo_table = Table([[logo_img]], colWidths=[40*mm]) + # Crear imagen con tamaño máximo, manteniendo proporciones + logo_img = RLImage(logo_bytes) + + # Ajustar tamaño manteniendo aspect ratio (máximo 50mm de ancho) + aspect = logo_img.imageHeight / float(logo_img.imageWidth) + logo_width = 50*mm + logo_height = logo_width * aspect + + # Si la altura es muy grande, ajustar por altura + if logo_height > 40*mm: + logo_height = 40*mm + logo_width = logo_height / aspect + + logo_img.drawWidth = logo_width + logo_img.drawHeight = logo_height + + logo_table = Table([[logo_img]], colWidths=[180*mm]) logo_table.setStyle(TableStyle([ ('ALIGN', (0, 0), (-1, -1), 'CENTER'), + ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ])) elements.append(logo_table) elements.append(Spacer(1, 5*mm)) + print(f"✅ Logo cargado correctamente ({logo_width/mm:.1f}mm x {logo_height/mm:.1f}mm)") + else: + print(f"❌ Error HTTP al cargar logo: {logo_resp.status_code}") except Exception as e: print(f"⚠️ Error cargando logo del checklist: {e}") + import traceback + traceback.print_exc() + else: + if not checklist: + print("⚠️ No se encontró el checklist") + elif not checklist.logo_url: + print("ℹ️ El checklist no tiene logo configurado") # Título con diseño moderno elements.append(Paragraph("📋 INFORME DE INSPECCIÓN VEHICULAR", title_style)) @@ -1666,10 +1695,10 @@ def generate_inspection_pdf(inspection_id: int, db: Session) -> str: if ans.comment: comment_text = ans.comment - # Limpiar prefijo de IA si existe - if "Análisis IA (" in comment_text and "): " in comment_text: - # Remover "Análisis IA (98% confianza): " - comment_text = comment_text.split("): ", 1)[1] if "): " in comment_text else comment_text + # Limpiar prefijo de IA si existe (con cualquier porcentaje) + import re + # Patrón para detectar "Análisis IA (XX% confianza): " con cualquier porcentaje + comment_text = re.sub(r'^Análisis IA \(\d+%\s+confianza\):\s*', '', comment_text) # Separar análisis y recomendaciones con salto de línea if "Recomendaciones:" in comment_text or "Recomendación:" in comment_text: