Se crea endpoint para procesar todos los pedimentos #3
@@ -41,7 +41,8 @@ from .views_auditor import (
|
|||||||
auditar_cove_pedimento_endpoint,
|
auditar_cove_pedimento_endpoint,
|
||||||
auditar_acuse_cove_pedimento_endpoint,
|
auditar_acuse_cove_pedimento_endpoint,
|
||||||
auditar_edocument_pedimento_endpoint,
|
auditar_edocument_pedimento_endpoint,
|
||||||
auditar_acuse_pedimento_endpoint
|
auditar_acuse_pedimento_endpoint,
|
||||||
|
auditor_procesar_pedimentos_organizacion
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
@@ -57,4 +58,5 @@ urlpatterns = [
|
|||||||
path('auditor/auditar-acuse-cove/pedimento/', auditar_acuse_cove_pedimento_endpoint, name='auditar-acuse-cove-pedimento'),
|
path('auditor/auditar-acuse-cove/pedimento/', auditar_acuse_cove_pedimento_endpoint, name='auditar-acuse-cove-pedimento'),
|
||||||
path('auditor/auditar-edocument/pedimento/', auditar_edocument_pedimento_endpoint, name='auditar-edocument-pedimento'),
|
path('auditor/auditar-edocument/pedimento/', auditar_edocument_pedimento_endpoint, name='auditar-edocument-pedimento'),
|
||||||
path('auditor/auditar-acuse/pedimento/', auditar_acuse_pedimento_endpoint, name='auditar-acuse-pedimento'),
|
path('auditor/auditar-acuse/pedimento/', auditar_acuse_pedimento_endpoint, name='auditar-acuse-pedimento'),
|
||||||
|
path('auditor/procesar-pedimentos/organizaciones/', auditor_procesar_pedimentos_organizacion, name='procesar-pedimentos-organizaciones'),
|
||||||
]
|
]
|
||||||
@@ -19,7 +19,9 @@ from .tasks.auditoria import (
|
|||||||
auditar_acuse_por_pedimento
|
auditar_acuse_por_pedimento
|
||||||
)
|
)
|
||||||
from .tasks.internal_services import auditar_pedimentos
|
from .tasks.internal_services import auditar_pedimentos
|
||||||
|
from .tasks.microservice_v2 import procesar_pedimentos_completos
|
||||||
from api.customs.models import Pedimento
|
from api.customs.models import Pedimento
|
||||||
|
from api.organization.models import Organizacion
|
||||||
|
|
||||||
|
|
||||||
@swagger_auto_schema(
|
@swagger_auto_schema(
|
||||||
@@ -547,6 +549,7 @@ def auditar_edocument_pedimento_endpoint(request):
|
|||||||
404: openapi.Response('Pedimento no encontrado')
|
404: openapi.Response('Pedimento no encontrado')
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@api_view(['POST'])
|
@api_view(['POST'])
|
||||||
@permission_classes([IsAuthenticated])
|
@permission_classes([IsAuthenticated])
|
||||||
def auditar_acuse_pedimento_endpoint(request):
|
def auditar_acuse_pedimento_endpoint(request):
|
||||||
@@ -563,4 +566,70 @@ def auditar_acuse_pedimento_endpoint(request):
|
|||||||
task = auditar_acuse_por_pedimento.delay(pedimento_id)
|
task = auditar_acuse_por_pedimento.delay(pedimento_id)
|
||||||
return Response({'message': f'Auditoría de acuse iniciada para el pedimento {pedimento_id}', 'task_id': task.id}, status=status.HTTP_200_OK)
|
return Response({'message': f'Auditoría de acuse iniciada para el pedimento {pedimento_id}', 'task_id': task.id}, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
### Procesamiento de pedimentos ###
|
||||||
|
@swagger_auto_schema(
|
||||||
|
method='post',
|
||||||
|
operation_description="Procesamiento de todos los pedimentos de todas las organizaciones",
|
||||||
|
request_body=openapi.Schema(
|
||||||
|
type=openapi.TYPE_OBJECT,
|
||||||
|
properties={}
|
||||||
|
),
|
||||||
|
responses={
|
||||||
|
200: openapi.Response('Tarea de procesamiento iniciada correctamente'),
|
||||||
|
403: openapi.Response('No tiene permisos suficientes'),
|
||||||
|
404: openapi.Response('No se encontraron organizaciones')
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@api_view(['POST'])
|
||||||
|
@permission_classes([IsAuthenticated & (IsSuperUser | IsSameOrganizationDeveloper)])
|
||||||
|
def auditor_procesar_pedimentos_organizacion(request):
|
||||||
|
"""
|
||||||
|
Inicia una tarea de procesamiento para todos los pedimentos de todas las organizaciones.
|
||||||
|
Solo usuarios administradores pueden ejecutar esta función.
|
||||||
|
"""
|
||||||
|
# Validar permisos (solo superusuarios pueden procesar todas las organizaciones)
|
||||||
|
user = request.user
|
||||||
|
if not user.is_superuser:
|
||||||
|
return Response(
|
||||||
|
{'error': 'Solo los superusuarios pueden procesar todas las organizaciones'},
|
||||||
|
status=status.HTTP_403_FORBIDDEN
|
||||||
|
)
|
||||||
|
|
||||||
|
organizaciones = Organizacion.objects.all()
|
||||||
|
if not organizaciones.exists():
|
||||||
|
return Response(
|
||||||
|
{'error': 'No se encontraron organizaciones'},
|
||||||
|
status=status.HTTP_404_NOT_FOUND
|
||||||
|
)
|
||||||
|
|
||||||
|
# Lista para recopilar todos los task_ids y detalles
|
||||||
|
tasks_iniciadas = []
|
||||||
|
|
||||||
|
for organizacion in organizaciones:
|
||||||
|
organizacion_id = str(organizacion.id)
|
||||||
|
print(f"Procesando organización: {organizacion_id} - {organizacion.nombre}")
|
||||||
|
# Ejecutar la tarea de procesamiento
|
||||||
|
task = procesar_pedimentos_completos.delay(organizacion_id)
|
||||||
|
|
||||||
|
# Agregar información de la tarea a la lista
|
||||||
|
tasks_iniciadas.append({
|
||||||
|
'organizacion_id': organizacion_id,
|
||||||
|
'organizacion_nombre': organizacion.nombre,
|
||||||
|
'task_id': task.id
|
||||||
|
})
|
||||||
|
|
||||||
|
# Crear mensaje general y lista de task_ids
|
||||||
|
total_organizaciones = len(tasks_iniciadas)
|
||||||
|
task_ids = [task['task_id'] for task in tasks_iniciadas]
|
||||||
|
|
||||||
|
message = f"Procesamiento de pedimentos iniciado para {total_organizaciones} organización(es)"
|
||||||
|
|
||||||
|
return Response({
|
||||||
|
'message': message,
|
||||||
|
'total_organizaciones': total_organizaciones,
|
||||||
|
'task_ids': task_ids,
|
||||||
|
'tasks_detalle': tasks_iniciadas
|
||||||
|
}, status=status.HTTP_200_OK)
|
||||||
|
### Fin Procesamiento de pedimentos ###
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user