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: