New alert service

This commit is contained in:
Urtzi Alfaro
2025-12-05 20:07:01 +01:00
parent 1fe3a73549
commit 667e6e0404
393 changed files with 26002 additions and 61033 deletions

View File

@@ -181,6 +181,33 @@ class DeliveryRouteRepository:
'updated_at': route.updated_at
}
async def get_all_routes_for_tenant(self, tenant_id: str) -> List[Dict[str, Any]]:
"""
Get all delivery routes for a tenant
"""
stmt = select(DeliveryRoute).where(DeliveryRoute.tenant_id == tenant_id)
result = await self.db_session.execute(stmt)
routes = result.scalars().all()
return [
{
'id': str(route.id),
'tenant_id': str(route.tenant_id),
'route_number': route.route_number,
'route_date': route.route_date,
'vehicle_id': route.vehicle_id,
'driver_id': route.driver_id,
'total_distance_km': route.total_distance_km,
'estimated_duration_minutes': route.estimated_duration_minutes,
'route_sequence': route.route_sequence,
'status': route.status.value if hasattr(route.status, 'value') else route.status,
'created_at': route.created_at,
'updated_at': route.updated_at
}
for route in routes
]
async def delete_demo_routes_for_tenant(self, tenant_id: str) -> int:
"""
Delete all demo routes for a tenant

View File

@@ -283,6 +283,42 @@ class ShipmentRepository:
'count': len(updated_shipments)
}
async def get_all_shipments_for_tenant(self, tenant_id: str) -> List[Dict[str, Any]]:
"""
Get all shipments for a tenant
"""
stmt = select(Shipment).where(Shipment.tenant_id == tenant_id)
result = await self.db_session.execute(stmt)
shipments = result.scalars().all()
return [
{
'id': str(shipment.id),
'tenant_id': str(shipment.tenant_id),
'parent_tenant_id': str(shipment.parent_tenant_id),
'child_tenant_id': str(shipment.child_tenant_id),
'purchase_order_id': str(shipment.purchase_order_id) if shipment.purchase_order_id else None,
'delivery_route_id': str(shipment.delivery_route_id) if shipment.delivery_route_id else None,
'shipment_number': shipment.shipment_number,
'shipment_date': shipment.shipment_date,
'current_location_lat': shipment.current_location_lat,
'current_location_lng': shipment.current_location_lng,
'last_tracked_at': shipment.last_tracked_at,
'status': shipment.status.value if hasattr(shipment.status, 'value') else shipment.status,
'actual_delivery_time': shipment.actual_delivery_time,
'signature': shipment.signature,
'photo_url': shipment.photo_url,
'received_by_name': shipment.received_by_name,
'delivery_notes': shipment.delivery_notes,
'total_weight_kg': shipment.total_weight_kg,
'total_volume_m3': shipment.total_volume_m3,
'created_at': shipment.created_at,
'updated_at': shipment.updated_at
}
for shipment in shipments
]
async def delete_demo_shipments_for_tenant(self, tenant_id: str) -> int:
"""
Delete all demo shipments for a tenant