se modifico tasks y views de auditor
This commit is contained in:
@@ -51,28 +51,6 @@ def auditor_descargas(pedimento, servicio, related_name, variable, mensaje):
|
||||
print(f"✗ No se encontró proceso de auditoría para pedimento {pedimento_id}.")
|
||||
|
||||
## Auditar pedimentos
|
||||
@shared_task
|
||||
def auditar_procesamiento_remesas(organizacion_id):
|
||||
pedimentos = obtener_pedimentos(organizacion_id)
|
||||
|
||||
for pedimento in pedimentos:
|
||||
if pedimento.remesas:
|
||||
# Tipo 3: Remesa
|
||||
if not pedimento.documents.filter(document_type=3).exists():
|
||||
ProcesamientoPedimento.objects.get_or_create(
|
||||
pedimento=pedimento,
|
||||
servicio_id=5, # ID del servicio de remesas
|
||||
organizacion=organizacion_id
|
||||
)
|
||||
else:
|
||||
xml_data = extraer_coves(pedimento)
|
||||
if xml_data:
|
||||
for remesa in xml_data:
|
||||
Cove.objects.get_or_create(
|
||||
pedimento=pedimento,
|
||||
numero_cove=remesa.get('remesaSA'),
|
||||
organizacion=organizacion_id
|
||||
)
|
||||
|
||||
@shared_task
|
||||
def auditar_procesamiento_remesa_por_pedimento(pedimento_id):
|
||||
@@ -259,4 +237,68 @@ def auditar_acuse(organizacion_id):
|
||||
variable='acuse_descargado',
|
||||
mensaje='acuse'
|
||||
)
|
||||
|
||||
|
||||
@shared_task
|
||||
def auditar_cove_por_pedimento(pedimento_id):
|
||||
try:
|
||||
from api.customs.models import Pedimento
|
||||
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||
auditor_descargas(
|
||||
pedimento,
|
||||
servicio=8,
|
||||
related_name='coves',
|
||||
variable='acuse_descargado',
|
||||
mensaje='COVE'
|
||||
)
|
||||
return {'success': True, 'pedimento_id': str(pedimento_id)}
|
||||
except Exception as e:
|
||||
return {'success': False, 'error': str(e), 'pedimento_id': str(pedimento_id)}
|
||||
|
||||
@shared_task
|
||||
def auditar_acuse_cove_por_pedimento(pedimento_id):
|
||||
try:
|
||||
from api.customs.models import Pedimento
|
||||
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||
auditor_descargas(
|
||||
pedimento,
|
||||
servicio=9,
|
||||
related_name='coves',
|
||||
variable='acuse_cove_descargado',
|
||||
mensaje='acuse de COVE'
|
||||
)
|
||||
return {'success': True, 'pedimento_id': str(pedimento_id)}
|
||||
except Exception as e:
|
||||
return {'success': False, 'error': str(e), 'pedimento_id': str(pedimento_id)}
|
||||
|
||||
@shared_task
|
||||
def auditar_edocument_por_pedimento(pedimento_id):
|
||||
try:
|
||||
from api.customs.models import Pedimento
|
||||
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||
auditor_descargas(
|
||||
pedimento,
|
||||
servicio=7,
|
||||
related_name='documentos',
|
||||
variable='edocument_descargado',
|
||||
mensaje='EDocument'
|
||||
)
|
||||
return {'success': True, 'pedimento_id': str(pedimento_id)}
|
||||
except Exception as e:
|
||||
return {'success': False, 'error': str(e), 'pedimento_id': str(pedimento_id)}
|
||||
|
||||
@shared_task
|
||||
def auditar_acuse_por_pedimento(pedimento_id):
|
||||
try:
|
||||
from api.customs.models import Pedimento
|
||||
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||
auditor_descargas(
|
||||
pedimento,
|
||||
servicio=6,
|
||||
related_name='documentos',
|
||||
variable='acuse_descargado',
|
||||
mensaje='acuse'
|
||||
)
|
||||
return {'success': True, 'pedimento_id': str(pedimento_id)}
|
||||
except Exception as e:
|
||||
return {'success': False, 'error': str(e), 'pedimento_id': str(pedimento_id)}
|
||||
|
||||
|
||||
@@ -218,6 +218,7 @@ def procesar_pedimentos_completos(organizacion_id):
|
||||
respuestas = []
|
||||
for pedimento in pedimentos:
|
||||
if not pedimento.documents.filter(document_type=2).exists(): # Tipo 2: Pedimento Completo
|
||||
input("Presiona Enter para continuar...")
|
||||
# Convertir el pedimento a JSON usando el serializer
|
||||
pedimento_dict = pedimento_to_dict(pedimento)
|
||||
credenciales = Vucem.objects.filter(id=CredencialesImportador.objects.filter(rfc=pedimento.contribuyente).first().vucem.id).first()
|
||||
@@ -265,7 +266,6 @@ def procesar_remesas(organizacion_id):
|
||||
|
||||
print(f"Servicio enviado para pedimento {pedimento.pedimento}")
|
||||
|
||||
|
||||
@shared_task
|
||||
def procesar_coves(organizacion_id):
|
||||
pedimentos = Pedimento.objects.filter(
|
||||
@@ -429,3 +429,5 @@ def documentos_con_errores(organizacion_id):
|
||||
# Aquí puedes agregar lógica adicional para manejar documentos con errores
|
||||
# como enviar notificaciones, registrar en un log, etc.
|
||||
# documentos = Document.objects.all() --- IGNORE ---
|
||||
|
||||
|
||||
|
||||
@@ -34,8 +34,14 @@ from .views_auditor import (
|
||||
crear_partidas_organizacion,
|
||||
crear_partidas_pedimento,
|
||||
auditar_pedimentos_endpoint,
|
||||
auditar_procesamiento_remesas_endpoint,
|
||||
auditar_procesamiento_remesa_pedimento_endpoint
|
||||
auditar_coves_endpoint,
|
||||
auditar_acuse_cove_endpoint,
|
||||
auditar_edocuments_endpoint,
|
||||
auditar_acuse_endpoint,
|
||||
auditar_cove_pedimento_endpoint,
|
||||
auditar_acuse_cove_pedimento_endpoint,
|
||||
auditar_edocument_pedimento_endpoint,
|
||||
auditar_acuse_pedimento_endpoint
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
@@ -43,6 +49,12 @@ urlpatterns = [
|
||||
path('auditor/crear-partidas/organizacion/', crear_partidas_organizacion, name='crear-partidas-organizacion'),
|
||||
path('auditor/crear-partidas/pedimento/', crear_partidas_pedimento, name='crear-partidas-pedimento'),
|
||||
path('auditor/auditar-pedimentos/', auditar_pedimentos_endpoint, name='auditar-pedimentos'),
|
||||
path('auditor/auditar-procesamiento-remesas/', auditar_procesamiento_remesas_endpoint, name='auditar-procesamiento-remesas'),
|
||||
path('auditor/auditar-procesamiento-remesa/pedimento/', auditar_procesamiento_remesa_pedimento_endpoint, name='auditar-procesamiento-remesa-pedimento'),
|
||||
path('auditor/auditar-coves/', auditar_coves_endpoint, name='auditar-coves'),
|
||||
path('auditor/auditar-acuse-cove/', auditar_acuse_cove_endpoint, name='auditar-acuse-cove'),
|
||||
path('auditor/auditar-edocuments/', auditar_edocuments_endpoint, name='auditar-edocuments'),
|
||||
path('auditor/auditar-acuse/', auditar_acuse_endpoint, name='auditar-acuse'),
|
||||
path('auditor/auditar-cove/pedimento/', auditar_cove_pedimento_endpoint, name='auditar-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-acuse/pedimento/', auditar_acuse_pedimento_endpoint, name='auditar-acuse-pedimento'),
|
||||
]
|
||||
@@ -8,8 +8,15 @@ from core.permissions import IsSuperUser, IsSameOrganizationDeveloper
|
||||
from .tasks.auditoria import (
|
||||
crear_partidas,
|
||||
crear_partidas_por_pedimento,
|
||||
auditar_procesamiento_remesas,
|
||||
auditar_procesamiento_remesa_por_pedimento
|
||||
auditar_procesamiento_remesa_por_pedimento,
|
||||
auditar_coves,
|
||||
auditar_acuse_cove,
|
||||
auditar_edocuments,
|
||||
auditar_acuse,
|
||||
auditar_cove_por_pedimento,
|
||||
auditar_acuse_cove_por_pedimento,
|
||||
auditar_edocument_por_pedimento,
|
||||
auditar_acuse_por_pedimento
|
||||
)
|
||||
from .tasks.internal_services import auditar_pedimentos
|
||||
from api.customs.models import Pedimento
|
||||
@@ -230,7 +237,7 @@ def auditar_procesamiento_remesa_pedimento_endpoint(request):
|
||||
|
||||
@swagger_auto_schema(
|
||||
method='post',
|
||||
operation_description="Audita el procesamiento de remesas de una organización",
|
||||
operation_description="Audita los COVEs de una organización",
|
||||
request_body=openapi.Schema(
|
||||
type=openapi.TYPE_OBJECT,
|
||||
properties={
|
||||
@@ -246,10 +253,10 @@ def auditar_procesamiento_remesa_pedimento_endpoint(request):
|
||||
)
|
||||
@api_view(['POST'])
|
||||
@permission_classes([IsAuthenticated & (IsSuperUser | IsSameOrganizationDeveloper)])
|
||||
def auditar_procesamiento_remesas_endpoint(request):
|
||||
def auditar_coves_endpoint(request):
|
||||
"""
|
||||
Inicia una tarea de auditoría para el procesamiento de remesas de una organización.
|
||||
Verifica el estado y la integridad del procesamiento de remesas.
|
||||
Inicia una tarea de auditoría para los COVEs de una organización.
|
||||
Verifica la existencia y validez de los COVEs generados.
|
||||
"""
|
||||
organizacion_id = request.data.get('organizacion_id')
|
||||
|
||||
@@ -268,8 +275,8 @@ def auditar_procesamiento_remesas_endpoint(request):
|
||||
)
|
||||
|
||||
# Ejecutar la tarea de auditoría
|
||||
task = auditar_procesamiento_remesas.delay(organizacion_id)
|
||||
message = f"Auditoría de procesamiento de remesas iniciada para la organización {organizacion_id}"
|
||||
task = auditar_coves.delay(organizacion_id)
|
||||
message = f"Auditoría de COVEs iniciada para la organización {organizacion_id}"
|
||||
|
||||
return Response({
|
||||
'message': message,
|
||||
@@ -277,3 +284,283 @@ def auditar_procesamiento_remesas_endpoint(request):
|
||||
}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
@swagger_auto_schema(
|
||||
method='post',
|
||||
operation_description="Audita los acuses de COVE de una organización",
|
||||
request_body=openapi.Schema(
|
||||
type=openapi.TYPE_OBJECT,
|
||||
properties={
|
||||
'organizacion_id': openapi.Schema(type=openapi.TYPE_STRING, description='ID de la organización')
|
||||
},
|
||||
required=['organizacion_id']
|
||||
),
|
||||
responses={
|
||||
200: openapi.Response('Tarea de auditoría iniciada correctamente'),
|
||||
400: openapi.Response('Error en los parámetros'),
|
||||
403: openapi.Response('No tiene permisos suficientes')
|
||||
}
|
||||
)
|
||||
@api_view(['POST'])
|
||||
@permission_classes([IsAuthenticated & (IsSuperUser | IsSameOrganizationDeveloper)])
|
||||
def auditar_acuse_cove_endpoint(request):
|
||||
"""
|
||||
Inicia una tarea de auditoría para los acuses de COVE de una organización.
|
||||
Verifica la recepción y validez de los acuses de COVE.
|
||||
"""
|
||||
organizacion_id = request.data.get('organizacion_id')
|
||||
|
||||
if not organizacion_id:
|
||||
return Response(
|
||||
{'error': 'Debe proporcionar organizacion_id'},
|
||||
status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
|
||||
# Validar permisos
|
||||
user = request.user
|
||||
if not user.is_superuser and str(user.organizacion.id) != organizacion_id:
|
||||
return Response(
|
||||
{'error': 'No tiene permisos para esta organización'},
|
||||
status=status.HTTP_403_FORBIDDEN
|
||||
)
|
||||
|
||||
# Ejecutar la tarea de auditoría
|
||||
task = auditar_acuse_cove.delay(organizacion_id)
|
||||
message = f"Auditoría de acuses de COVE iniciada para la organización {organizacion_id}"
|
||||
|
||||
return Response({
|
||||
'message': message,
|
||||
'task_id': task.id
|
||||
}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
@swagger_auto_schema(
|
||||
method='post',
|
||||
operation_description="Audita los EDocuments de una organización",
|
||||
request_body=openapi.Schema(
|
||||
type=openapi.TYPE_OBJECT,
|
||||
properties={
|
||||
'organizacion_id': openapi.Schema(type=openapi.TYPE_STRING, description='ID de la organización')
|
||||
},
|
||||
required=['organizacion_id']
|
||||
),
|
||||
responses={
|
||||
200: openapi.Response('Tarea de auditoría iniciada correctamente'),
|
||||
400: openapi.Response('Error en los parámetros'),
|
||||
403: openapi.Response('No tiene permisos suficientes')
|
||||
}
|
||||
)
|
||||
@api_view(['POST'])
|
||||
@permission_classes([IsAuthenticated & (IsSuperUser | IsSameOrganizationDeveloper)])
|
||||
def auditar_edocuments_endpoint(request):
|
||||
"""
|
||||
Inicia una tarea de auditoría para los EDocuments de una organización.
|
||||
Verifica la existencia y validez de los EDocuments generados.
|
||||
"""
|
||||
organizacion_id = request.data.get('organizacion_id')
|
||||
|
||||
if not organizacion_id:
|
||||
return Response(
|
||||
{'error': 'Debe proporcionar organizacion_id'},
|
||||
status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
|
||||
# Validar permisos
|
||||
user = request.user
|
||||
if not user.is_superuser and str(user.organizacion.id) != organizacion_id:
|
||||
return Response(
|
||||
{'error': 'No tiene permisos para esta organización'},
|
||||
status=status.HTTP_403_FORBIDDEN
|
||||
)
|
||||
|
||||
# Ejecutar la tarea de auditoría
|
||||
task = auditar_edocuments.delay(organizacion_id)
|
||||
message = f"Auditoría de EDocuments iniciada para la organización {organizacion_id}"
|
||||
|
||||
return Response({
|
||||
'message': message,
|
||||
'task_id': task.id
|
||||
}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
@swagger_auto_schema(
|
||||
method='post',
|
||||
operation_description="Audita los acuses de una organización",
|
||||
request_body=openapi.Schema(
|
||||
type=openapi.TYPE_OBJECT,
|
||||
properties={
|
||||
'organizacion_id': openapi.Schema(type=openapi.TYPE_STRING, description='ID de la organización')
|
||||
},
|
||||
required=['organizacion_id']
|
||||
),
|
||||
responses={
|
||||
200: openapi.Response('Tarea de auditoría iniciada correctamente'),
|
||||
400: openapi.Response('Error en los parámetros'),
|
||||
403: openapi.Response('No tiene permisos suficientes')
|
||||
}
|
||||
)
|
||||
@api_view(['POST'])
|
||||
@permission_classes([IsAuthenticated & (IsSuperUser | IsSameOrganizationDeveloper)])
|
||||
def auditar_acuse_endpoint(request):
|
||||
"""
|
||||
Inicia una tarea de auditoría para los acuses de una organización.
|
||||
Verifica la recepción y validez de los acuses.
|
||||
"""
|
||||
organizacion_id = request.data.get('organizacion_id')
|
||||
|
||||
if not organizacion_id:
|
||||
return Response(
|
||||
{'error': 'Debe proporcionar organizacion_id'},
|
||||
status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
|
||||
# Validar permisos
|
||||
user = request.user
|
||||
if not user.is_superuser and str(user.organizacion.id) != organizacion_id:
|
||||
return Response(
|
||||
{'error': 'No tiene permisos para esta organización'},
|
||||
status=status.HTTP_403_FORBIDDEN
|
||||
)
|
||||
|
||||
# Ejecutar la tarea de auditoría
|
||||
task = auditar_acuse.delay(organizacion_id)
|
||||
message = f"Auditoría de acuses iniciada para la organización {organizacion_id}"
|
||||
|
||||
return Response({
|
||||
'message': message,
|
||||
'task_id': task.id
|
||||
}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
@swagger_auto_schema(
|
||||
method='post',
|
||||
operation_description="Audita el COVE de un pedimento específico",
|
||||
request_body=openapi.Schema(
|
||||
type=openapi.TYPE_OBJECT,
|
||||
properties={
|
||||
'pedimento_id': openapi.Schema(type=openapi.TYPE_STRING, description='ID del pedimento')
|
||||
},
|
||||
required=['pedimento_id']
|
||||
),
|
||||
responses={
|
||||
200: openapi.Response('Tarea de auditoría iniciada correctamente'),
|
||||
400: openapi.Response('Error en los parámetros'),
|
||||
403: openapi.Response('No tiene permisos suficientes'),
|
||||
404: openapi.Response('Pedimento no encontrado')
|
||||
}
|
||||
)
|
||||
@api_view(['POST'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
def auditar_cove_pedimento_endpoint(request):
|
||||
pedimento_id = request.data.get('pedimento_id')
|
||||
if not pedimento_id:
|
||||
return Response({'error': 'Debe proporcionar pedimento_id'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
try:
|
||||
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||
user = request.user
|
||||
if not user.is_superuser and str(pedimento.organizacion.id) != str(user.organizacion.id):
|
||||
return Response({'error': 'No tiene permisos para este pedimento'}, status=status.HTTP_403_FORBIDDEN)
|
||||
except Pedimento.DoesNotExist:
|
||||
return Response({'error': 'Pedimento no encontrado'}, status=status.HTTP_404_NOT_FOUND)
|
||||
task = auditar_cove_por_pedimento.delay(pedimento_id)
|
||||
return Response({'message': f'Auditoría de COVE iniciada para el pedimento {pedimento_id}', 'task_id': task.id}, status=status.HTTP_200_OK)
|
||||
|
||||
@swagger_auto_schema(
|
||||
method='post',
|
||||
operation_description="Audita el acuse de COVE de un pedimento específico",
|
||||
request_body=openapi.Schema(
|
||||
type=openapi.TYPE_OBJECT,
|
||||
properties={
|
||||
'pedimento_id': openapi.Schema(type=openapi.TYPE_STRING, description='ID del pedimento')
|
||||
},
|
||||
required=['pedimento_id']
|
||||
),
|
||||
responses={
|
||||
200: openapi.Response('Tarea de auditoría iniciada correctamente'),
|
||||
400: openapi.Response('Error en los parámetros'),
|
||||
403: openapi.Response('No tiene permisos suficientes'),
|
||||
404: openapi.Response('Pedimento no encontrado')
|
||||
}
|
||||
)
|
||||
@api_view(['POST'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
def auditar_acuse_cove_pedimento_endpoint(request):
|
||||
pedimento_id = request.data.get('pedimento_id')
|
||||
if not pedimento_id:
|
||||
return Response({'error': 'Debe proporcionar pedimento_id'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
try:
|
||||
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||
user = request.user
|
||||
if not user.is_superuser and str(pedimento.organizacion.id) != str(user.organizacion.id):
|
||||
return Response({'error': 'No tiene permisos para este pedimento'}, status=status.HTTP_403_FORBIDDEN)
|
||||
except Pedimento.DoesNotExist:
|
||||
return Response({'error': 'Pedimento no encontrado'}, status=status.HTTP_404_NOT_FOUND)
|
||||
task = auditar_acuse_cove_por_pedimento.delay(pedimento_id)
|
||||
return Response({'message': f'Auditoría de acuse de COVE iniciada para el pedimento {pedimento_id}', 'task_id': task.id}, status=status.HTTP_200_OK)
|
||||
|
||||
@swagger_auto_schema(
|
||||
method='post',
|
||||
operation_description="Audita el EDocument de un pedimento específico",
|
||||
request_body=openapi.Schema(
|
||||
type=openapi.TYPE_OBJECT,
|
||||
properties={
|
||||
'pedimento_id': openapi.Schema(type=openapi.TYPE_STRING, description='ID del pedimento')
|
||||
},
|
||||
required=['pedimento_id']
|
||||
),
|
||||
responses={
|
||||
200: openapi.Response('Tarea de auditoría iniciada correctamente'),
|
||||
400: openapi.Response('Error en los parámetros'),
|
||||
403: openapi.Response('No tiene permisos suficientes'),
|
||||
404: openapi.Response('Pedimento no encontrado')
|
||||
}
|
||||
)
|
||||
@api_view(['POST'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
def auditar_edocument_pedimento_endpoint(request):
|
||||
pedimento_id = request.data.get('pedimento_id')
|
||||
if not pedimento_id:
|
||||
return Response({'error': 'Debe proporcionar pedimento_id'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
try:
|
||||
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||
user = request.user
|
||||
if not user.is_superuser and str(pedimento.organizacion.id) != str(user.organizacion.id):
|
||||
return Response({'error': 'No tiene permisos para este pedimento'}, status=status.HTTP_403_FORBIDDEN)
|
||||
except Pedimento.DoesNotExist:
|
||||
return Response({'error': 'Pedimento no encontrado'}, status=status.HTTP_404_NOT_FOUND)
|
||||
task = auditar_edocument_por_pedimento.delay(pedimento_id)
|
||||
return Response({'message': f'Auditoría de EDocument iniciada para el pedimento {pedimento_id}', 'task_id': task.id}, status=status.HTTP_200_OK)
|
||||
|
||||
@swagger_auto_schema(
|
||||
method='post',
|
||||
operation_description="Audita el acuse de un pedimento específico",
|
||||
request_body=openapi.Schema(
|
||||
type=openapi.TYPE_OBJECT,
|
||||
properties={
|
||||
'pedimento_id': openapi.Schema(type=openapi.TYPE_STRING, description='ID del pedimento')
|
||||
},
|
||||
required=['pedimento_id']
|
||||
),
|
||||
responses={
|
||||
200: openapi.Response('Tarea de auditoría iniciada correctamente'),
|
||||
400: openapi.Response('Error en los parámetros'),
|
||||
403: openapi.Response('No tiene permisos suficientes'),
|
||||
404: openapi.Response('Pedimento no encontrado')
|
||||
}
|
||||
)
|
||||
@api_view(['POST'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
def auditar_acuse_pedimento_endpoint(request):
|
||||
pedimento_id = request.data.get('pedimento_id')
|
||||
if not pedimento_id:
|
||||
return Response({'error': 'Debe proporcionar pedimento_id'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
try:
|
||||
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||
user = request.user
|
||||
if not user.is_superuser and str(pedimento.organizacion.id) != str(user.organizacion.id):
|
||||
return Response({'error': 'No tiene permisos para este pedimento'}, status=status.HTTP_403_FORBIDDEN)
|
||||
except Pedimento.DoesNotExist:
|
||||
return Response({'error': 'Pedimento no encontrado'}, status=status.HTTP_404_NOT_FOUND)
|
||||
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)
|
||||
|
||||
|
||||
|
||||
14
api/tasks/filters.py
Normal file
14
api/tasks/filters.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from django_filters import rest_framework as filters
|
||||
from .models import Task
|
||||
|
||||
class TaskFilter(filters.FilterSet):
|
||||
servicio = filters.NumberFilter(field_name='servicio__id')
|
||||
pedimento_app = filters.CharFilter(field_name='pedimento__pedimento_app')
|
||||
pedimento = filters.UUIDFilter(field_name='pedimento__id')
|
||||
timestamp_gte = filters.DateTimeFilter(field_name='timestamp', lookup_expr='gte')
|
||||
timestamp_lte = filters.DateTimeFilter(field_name='timestamp', lookup_expr='lte')
|
||||
status = filters.CharFilter(field_name='status')
|
||||
|
||||
class Meta:
|
||||
model = Task
|
||||
fields = ['servicio', 'pedimento_app', 'pedimento', 'timestamp_gte', 'timestamp_lte', 'status']
|
||||
@@ -9,3 +9,4 @@ class Task(models.Model):
|
||||
message = models.TextField()
|
||||
status = models.CharField(max_length=50)
|
||||
servicio = models.ForeignKey('customs.Servicio', on_delete=models.CASCADE, null=True, blank=True)
|
||||
|
||||
@@ -2,6 +2,8 @@ from rest_framework import serializers
|
||||
from .models import Task
|
||||
|
||||
class TaskSerializer(serializers.ModelSerializer):
|
||||
pedimento_app = serializers.CharField(source='pedimento.pedimento_app', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Task
|
||||
fields = '__all__'
|
||||
@@ -1,9 +1,12 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework import viewsets
|
||||
from rest_framework import viewsets, filters
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
|
||||
from api.logger.mixins import LoggingMixin
|
||||
from .models import Task
|
||||
from .serializers import TaskSerializer
|
||||
from .filters import TaskFilter
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
|
||||
# Create your views here.
|
||||
@@ -14,9 +17,19 @@ from core.permissions import (
|
||||
IsSuperUser
|
||||
)
|
||||
|
||||
class TaskPagination(PageNumberPagination):
|
||||
page_size = 10
|
||||
page_size_query_param = 'page_size'
|
||||
max_page_size = 100
|
||||
|
||||
class TaskViewSet(LoggingMixin,viewsets.ModelViewSet):
|
||||
permission_classes = [IsAuthenticated & (IsSameOrganization | IsSameOrganizationAndAdmin | IsSameOrganizationDeveloper | IsSuperUser)]
|
||||
queryset = Task.objects.all()
|
||||
queryset = Task.objects.select_related('pedimento', 'servicio').all()
|
||||
serializer_class = TaskSerializer
|
||||
filter_backends = [DjangoFilterBackend, filters.OrderingFilter]
|
||||
filterset_class = TaskFilter
|
||||
pagination_class = TaskPagination
|
||||
ordering_fields = ['timestamp']
|
||||
ordering = ['-timestamp'] # ordenamiento por defecto, más reciente primero
|
||||
|
||||
my_tags = ['tasks']
|
||||
@@ -3,46 +3,7 @@ from celery.schedules import crontab
|
||||
|
||||
|
||||
CELERY_BEAT_SCHEDULE = {
|
||||
# Ejecutar pedimento completo de 5:00 a 22:00 (cada hora)
|
||||
'creacion-servicio-pedimento-completo': {
|
||||
'task': 'api.customs.tasks.internal_services.crear_todos_los_servicios',
|
||||
'schedule': crontab(minute=0, hour='5-22'),
|
||||
},
|
||||
# Ejecutar pedimento completo de 5:00 a 22:00 (cada hora)
|
||||
'ejecutar-pedimentos-completos-dia': {
|
||||
'task': 'api.customs.tasks.microservice.ejecutar_pedimento_completo',
|
||||
'schedule': crontab(minute=0, hour='5-22'),
|
||||
},
|
||||
# Ejecutar partidas de 5:00 a 22:00 (cada hora)
|
||||
'ejecutar-partidas-dia': {
|
||||
'task': 'api.customs.tasks.microservice.ejecutar_partidas_pedimento',
|
||||
'schedule': crontab(minute=0, hour='5-23'),
|
||||
},
|
||||
# Ejecutar coves de 5:00 a 22:00 (cada hora)
|
||||
'ejecutar-coves-dia': {
|
||||
'task': 'api.customs.tasks.microservice.ejecutar_coves',
|
||||
'schedule': crontab(minute=0, hour='5-23'),
|
||||
},
|
||||
# Ejecutar remesas de 5:00 a 22:00 (cada hora)
|
||||
'ejecutar-remesas-dia': {
|
||||
'task': 'api.customs.tasks.microservice.ejecutar_remesas',
|
||||
'schedule': crontab(minute=0, hour='5-23'),
|
||||
},
|
||||
# Ejecutar acuse coves de 5:00 a 22:00 (cada hora)
|
||||
'ejecutar-acuse-coves-dia': {
|
||||
'task': 'api.customs.tasks.microservice.ejecutar_acuseCoves',
|
||||
'schedule': crontab(minute=0, hour='5-23'),
|
||||
},
|
||||
# Ejecutar acuse de 5:00 a 22:00 (cada hora)
|
||||
'ejecutar-acuse-dia': {
|
||||
'task': 'api.customs.tasks.microservice.ejecutar_acuse',
|
||||
'schedule': crontab(minute=0, hour='5-23'),
|
||||
},
|
||||
# Ejecutar edocs solo de 23:00 a 4:59 (cada hora en ese rango)
|
||||
'ejecutar-edocs-noche': {
|
||||
'task': 'api.customs.tasks.microservice.ejecutar_edocs',
|
||||
'schedule': crontab(minute=42, hour='23,0,1,2,3,4'),
|
||||
},
|
||||
|
||||
|
||||
}
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user