Fix some issues
This commit is contained in:
@@ -480,12 +480,32 @@ async def trigger_failure_notifications(notification_service: any, tenant_id: UU
|
||||
}
|
||||
|
||||
html_content = template.render(**template_vars)
|
||||
text_content = f"Equipment failure alert: {equipment.name} - {failure_data.get('failureType', 'Unknown')}"
|
||||
|
||||
# Send via notification service (which will handle the actual email sending)
|
||||
# This is a simplified approach - in production you'd want to get manager emails from DB
|
||||
logger.info("Failure notifications triggered (template rendered)",
|
||||
equipment_id=str(equipment.id),
|
||||
tenant_id=str(tenant_id))
|
||||
# Send via notification service API
|
||||
if notification_service:
|
||||
result = await notification_service.send_email(
|
||||
tenant_id=str(tenant_id),
|
||||
to_email="managers@bakeryia.com", # Should be configured from DB in production
|
||||
subject=f"🚨 Fallo de Equipo: {equipment.name}",
|
||||
message=text_content,
|
||||
html_content=html_content,
|
||||
priority="high"
|
||||
)
|
||||
|
||||
if result:
|
||||
logger.info("Failure notifications sent via notification service",
|
||||
equipment_id=str(equipment.id),
|
||||
tenant_id=str(tenant_id),
|
||||
notification_id=result.get('notification_id'))
|
||||
else:
|
||||
logger.error("Failed to send failure notifications via notification service",
|
||||
equipment_id=str(equipment.id),
|
||||
tenant_id=str(tenant_id))
|
||||
else:
|
||||
logger.warning("Notification service not available, failure notifications not sent",
|
||||
equipment_id=str(equipment.id),
|
||||
tenant_id=str(tenant_id))
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Error triggering failure notifications",
|
||||
@@ -523,11 +543,32 @@ async def trigger_repair_notifications(notification_service: any, tenant_id: UUI
|
||||
}
|
||||
|
||||
html_content = template.render(**template_vars)
|
||||
text_content = f"Equipment repair completed: {equipment.name} - {repair_data.get('repairDescription', 'Repair completed')}"
|
||||
|
||||
# Send via notification service
|
||||
logger.info("Repair notifications triggered (template rendered)",
|
||||
equipment_id=str(equipment.id),
|
||||
tenant_id=str(tenant_id))
|
||||
# Send via notification service API
|
||||
if notification_service:
|
||||
result = await notification_service.send_email(
|
||||
tenant_id=str(tenant_id),
|
||||
to_email="managers@bakeryia.com", # Should be configured from DB in production
|
||||
subject=f"✅ Equipo Reparado: {equipment.name}",
|
||||
message=text_content,
|
||||
html_content=html_content,
|
||||
priority="normal"
|
||||
)
|
||||
|
||||
if result:
|
||||
logger.info("Repair notifications sent via notification service",
|
||||
equipment_id=str(equipment.id),
|
||||
tenant_id=str(tenant_id),
|
||||
notification_id=result.get('notification_id'))
|
||||
else:
|
||||
logger.error("Failed to send repair notifications via notification service",
|
||||
equipment_id=str(equipment.id),
|
||||
tenant_id=str(tenant_id))
|
||||
else:
|
||||
logger.warning("Notification service not available, repair notifications not sent",
|
||||
equipment_id=str(equipment.id),
|
||||
tenant_id=str(tenant_id))
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Error triggering repair notifications",
|
||||
@@ -565,14 +606,35 @@ async def send_support_contact_notification(notification_service: any, tenant_id
|
||||
}
|
||||
|
||||
html_content = template.render(**template_vars)
|
||||
text_content = f"Equipment failure alert: {equipment.name} - {failure_data.get('failureType', 'Unknown')}"
|
||||
|
||||
# TODO: Actually send email via notification service
|
||||
# For now, just log that we would send to the support email
|
||||
logger.info("Support contact notification prepared (would send to support)",
|
||||
equipment_id=str(equipment.id),
|
||||
tenant_id=str(tenant_id),
|
||||
support_email=support_email,
|
||||
subject=f"🚨 URGENTE: Fallo de Equipo - {equipment.name}")
|
||||
# Send via notification service API
|
||||
if notification_service and support_email:
|
||||
result = await notification_service.send_email(
|
||||
tenant_id=str(tenant_id),
|
||||
to_email=support_email,
|
||||
subject=f"🚨 URGENTE: Fallo de Equipo - {equipment.name}",
|
||||
message=text_content,
|
||||
html_content=html_content,
|
||||
priority="high"
|
||||
)
|
||||
|
||||
if result:
|
||||
logger.info("Support contact notification sent via notification service",
|
||||
equipment_id=str(equipment.id),
|
||||
tenant_id=str(tenant_id),
|
||||
support_email=support_email,
|
||||
notification_id=result.get('notification_id'))
|
||||
else:
|
||||
logger.error("Failed to send support contact notification via notification service",
|
||||
equipment_id=str(equipment.id),
|
||||
tenant_id=str(tenant_id),
|
||||
support_email=support_email)
|
||||
else:
|
||||
logger.warning("Notification service not available or no support email provided",
|
||||
equipment_id=str(equipment.id),
|
||||
tenant_id=str(tenant_id),
|
||||
support_email=support_email)
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Error sending support contact notification",
|
||||
|
||||
Reference in New Issue
Block a user