Delete legacy alerts

This commit is contained in:
Urtzi Alfaro
2025-08-22 15:31:52 +02:00
parent c6dd6fd1de
commit 90100a66c6
40 changed files with 25 additions and 3308 deletions

View File

@@ -17,7 +17,6 @@ from shared.clients import (
ProductionServiceClient,
SalesServiceClient
)
from shared.notifications.alert_integration import AlertIntegration
from shared.database.transactions import transactional
from app.core.config import settings
@@ -52,7 +51,6 @@ class OrdersService:
inventory_client: InventoryServiceClient,
production_client: ProductionServiceClient,
sales_client: SalesServiceClient,
alert_integration: AlertIntegration
):
self.order_repo = order_repo
self.customer_repo = customer_repo
@@ -61,7 +59,6 @@ class OrdersService:
self.inventory_client = inventory_client
self.production_client = production_client
self.sales_client = sales_client
self.alert_integration = alert_integration
@transactional
async def create_order(
@@ -137,8 +134,6 @@ class OrdersService:
if business_model:
order.business_model = business_model
# 9. Check for high-value or rush orders for alerts
await self._check_order_alerts(db, order, order_data.tenant_id)
# 10. Integrate with production service if auto-processing is enabled
if settings.ORDER_PROCESSING_ENABLED:
@@ -440,46 +435,6 @@ class OrdersService:
# Fallback to UUID
return f"ORD-{uuid.uuid4().hex[:8].upper()}"
async def _check_order_alerts(self, db, order, tenant_id: UUID):
"""Check for conditions that require alerts"""
try:
alerts = []
# High-value order alert
if order.total_amount > settings.HIGH_VALUE_ORDER_THRESHOLD:
alerts.append({
"type": "high_value_order",
"severity": "medium",
"message": f"High-value order created: ${order.total_amount}"
})
# Rush order alert
if order.order_type == "rush":
time_to_delivery = order.requested_delivery_date - order.order_date
if time_to_delivery.total_seconds() < settings.RUSH_ORDER_HOURS_THRESHOLD * 3600:
alerts.append({
"type": "rush_order",
"severity": "high",
"message": f"Rush order with tight deadline: {order.order_number}"
})
# Large quantity alert
total_items = sum(item.quantity for item in order.items)
if total_items > settings.LARGE_QUANTITY_ORDER_THRESHOLD:
alerts.append({
"type": "large_quantity_order",
"severity": "medium",
"message": f"Large quantity order: {total_items} items"
})
# Send alerts if any
for alert in alerts:
await self._send_alert(tenant_id, order.id, alert)
except Exception as e:
logger.error("Error checking order alerts",
order_id=str(order.id),
error=str(e))
async def _notify_production_service(self, order):
"""Notify production service of new order"""
@@ -526,21 +481,3 @@ class OrdersService:
order_id=str(order.id),
error=str(e))
async def _send_alert(self, tenant_id: UUID, order_id: UUID, alert: Dict[str, Any]):
"""Send alert notification"""
try:
if self.notification_client:
await self.notification_client.send_alert(
str(tenant_id),
{
"alert_type": alert["type"],
"severity": alert["severity"],
"message": alert["message"],
"source_entity_id": str(order_id),
"source_entity_type": "order"
}
)
except Exception as e:
logger.warning("Failed to send alert",
tenant_id=str(tenant_id),
error=str(e))