Se agrego filtro de organizacion a datastage y pedimentos
This commit is contained in:
@@ -54,6 +54,143 @@ def partida_to_dict(partida):
|
|||||||
"numero": partida.numero_partida,
|
"numero": partida.numero_partida,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def procesar_coves_pedimento(pedimento_id):
|
||||||
|
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||||
|
if pedimento.coves.filter(cove_descargado=False).exists():
|
||||||
|
pedimento_dict = pedimento_to_dict(pedimento)
|
||||||
|
credenciales = Vucem.objects.filter(
|
||||||
|
id=CredencialesImportador.objects.filter(rfc=pedimento.contribuyente).first().vucem.id
|
||||||
|
).first()
|
||||||
|
credenciales_dict = credenciales_to_dict(credenciales)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"coves": [cove_to_dict(cove) for cove in pedimento.coves.filter(cove_descargado=False)],
|
||||||
|
"pedimento": pedimento_dict,
|
||||||
|
"credencial": credenciales_dict
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(
|
||||||
|
f"{SERVICE_API_URL_V2}/services/all/coves",
|
||||||
|
data=json.dumps(payload),
|
||||||
|
headers={"Content-Type": "application/json"}
|
||||||
|
)
|
||||||
|
print(f"Servicio de COVEs enviado para pedimento {pedimento.pedimento}")
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def procesar_acuse_coves_pedimento(pedimento_id):
|
||||||
|
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||||
|
if pedimento.coves.filter(acuse_cove_descargado=False).exists():
|
||||||
|
pedimento_dict = pedimento_to_dict(pedimento)
|
||||||
|
credenciales = Vucem.objects.filter(
|
||||||
|
id=CredencialesImportador.objects.filter(rfc=pedimento.contribuyente).first().vucem.id
|
||||||
|
).first()
|
||||||
|
credenciales_dict = credenciales_to_dict(credenciales)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"coves": [cove_to_dict(cove) for cove in pedimento.coves.filter(acuse_cove_descargado=False)],
|
||||||
|
"pedimento": pedimento_dict,
|
||||||
|
"credencial": credenciales_dict
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(
|
||||||
|
f"{SERVICE_API_URL_V2}/services/all/acuse/cove/",
|
||||||
|
data=json.dumps(payload),
|
||||||
|
headers={"Content-Type": "application/json"}
|
||||||
|
)
|
||||||
|
print(f"Servicio de acuses de COVEs enviado para pedimento {pedimento.pedimento}")
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def procesar_edocs_pedimento(pedimento_id):
|
||||||
|
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||||
|
if pedimento.documentos.filter(edocument_descargado=False).exists():
|
||||||
|
pedimento_dict = pedimento_to_dict(pedimento)
|
||||||
|
credenciales = Vucem.objects.filter(
|
||||||
|
id=CredencialesImportador.objects.filter(rfc=pedimento.contribuyente).first().vucem.id
|
||||||
|
).first()
|
||||||
|
credenciales_dict = credenciales_to_dict(credenciales)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"edocs": [edoc_to_dict(edoc) for edoc in pedimento.documentos.filter(edocument_descargado=False)],
|
||||||
|
"pedimento": pedimento_dict,
|
||||||
|
"credencial": credenciales_dict
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(
|
||||||
|
f"{SERVICE_API_URL_V2}/services/all/acuse/pedimento/",
|
||||||
|
data=json.dumps(payload),
|
||||||
|
headers={"Content-Type": "application/json"}
|
||||||
|
)
|
||||||
|
print(f"Servicio de E-documents enviado para pedimento {pedimento.pedimento}")
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def procesar_acuses_pedimento(pedimento_id):
|
||||||
|
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||||
|
if pedimento.documentos.filter(acuse_descargado=False).exists():
|
||||||
|
pedimento_dict = pedimento_to_dict(pedimento)
|
||||||
|
credenciales = Vucem.objects.filter(
|
||||||
|
id=CredencialesImportador.objects.filter(rfc=pedimento.contribuyente).first().vucem.id
|
||||||
|
).first()
|
||||||
|
credenciales_dict = credenciales_to_dict(credenciales)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"edocs": [edoc_to_dict(edoc) for edoc in pedimento.documentos.filter(acuse_descargado=False)],
|
||||||
|
"pedimento": pedimento_dict,
|
||||||
|
"credencial": credenciales_dict
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(
|
||||||
|
f"{SERVICE_API_URL_V2}/services/all/acuse/pedimento/",
|
||||||
|
data=json.dumps(payload),
|
||||||
|
headers={"Content-Type": "application/json"}
|
||||||
|
)
|
||||||
|
print(f"Servicio de acuses enviado para pedimento {pedimento.pedimento}")
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def procesar_partidas_pedimento(pedimento_id):
|
||||||
|
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||||
|
if pedimento.partidas.filter(descargado=False).exists():
|
||||||
|
pedimento_dict = pedimento_to_dict(pedimento)
|
||||||
|
credenciales = Vucem.objects.filter(
|
||||||
|
id=CredencialesImportador.objects.filter(rfc=pedimento.contribuyente).first().vucem.id
|
||||||
|
).first()
|
||||||
|
credenciales_dict = credenciales_to_dict(credenciales)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"partidas": [partida_to_dict(partida) for partida in pedimento.partidas.filter(descargado=False)],
|
||||||
|
"pedimento": pedimento_dict,
|
||||||
|
"credencial": credenciales_dict
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(
|
||||||
|
f"{SERVICE_API_URL_V2}/services/all/partidas/",
|
||||||
|
data=json.dumps(payload),
|
||||||
|
headers={"Content-Type": "application/json"}
|
||||||
|
)
|
||||||
|
print(f"Servicio de partidas enviado para pedimento {pedimento.pedimento}")
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def procesar_remesas_pedimento(pedimento_id):
|
||||||
|
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||||
|
if not pedimento.documents.filter(document_type=3).exists(): # Tipo 3: Remesa
|
||||||
|
pedimento_dict = pedimento_to_dict(pedimento)
|
||||||
|
credenciales = Vucem.objects.filter(
|
||||||
|
id=CredencialesImportador.objects.filter(rfc=pedimento.contribuyente).first().vucem.id
|
||||||
|
).first()
|
||||||
|
credenciales_dict = credenciales_to_dict(credenciales)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"pedimento": pedimento_dict,
|
||||||
|
"credencial": credenciales_dict
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(
|
||||||
|
f"{SERVICE_API_URL_V2}/services/remesas",
|
||||||
|
data=json.dumps(payload),
|
||||||
|
headers={"Content-Type": "application/json"}
|
||||||
|
)
|
||||||
|
print(f"Servicio de remesas enviado para pedimento {pedimento.pedimento}")
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def procesar_pedimento_completo_individual(pedimento_id):
|
def procesar_pedimento_completo_individual(pedimento_id):
|
||||||
pedimento = Pedimento.objects.get(id=pedimento_id)
|
pedimento = Pedimento.objects.get(id=pedimento_id)
|
||||||
@@ -74,17 +211,6 @@ def procesar_pedimento_completo_individual(pedimento_id):
|
|||||||
)
|
)
|
||||||
print(f"Servicio enviado para pedimento {pedimento.pedimento}")
|
print(f"Servicio enviado para pedimento {pedimento.pedimento}")
|
||||||
|
|
||||||
def procesar_pedimentos_completos_en_lotes(organizacion_id, batch_size=20):
|
|
||||||
pedimentos = Pedimento.objects.filter(organizacion_id=organizacion_id)
|
|
||||||
ids = list(pedimentos.values_list('id', flat=True))
|
|
||||||
for i in range(0, len(ids), batch_size):
|
|
||||||
batch = ids[i:i+batch_size]
|
|
||||||
job = group(
|
|
||||||
procesar_pedimento_completo_individual.s(ped_id)
|
|
||||||
for ped_id in batch
|
|
||||||
)
|
|
||||||
job.apply_async()
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def procesar_pedimentos_completos(organizacion_id):
|
def procesar_pedimentos_completos(organizacion_id):
|
||||||
pedimentos = Pedimento.objects.filter(organizacion_id=organizacion_id)
|
pedimentos = Pedimento.objects.filter(organizacion_id=organizacion_id)
|
||||||
@@ -111,7 +237,6 @@ def procesar_pedimentos_completos(organizacion_id):
|
|||||||
# Aquí puedes continuar con el resto de tu lógica
|
# Aquí puedes continuar con el resto de tu lógica
|
||||||
print(f"Servicio enviado para pedimento {pedimento.pedimento}")
|
print(f"Servicio enviado para pedimento {pedimento.pedimento}")
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def procesar_remesas(organizacion_id):
|
def procesar_remesas(organizacion_id):
|
||||||
pedimentos = Pedimento.objects.filter(organizacion_id=organizacion_id)
|
pedimentos = Pedimento.objects.filter(organizacion_id=organizacion_id)
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from .views import ExportModelView, dashboard_summary
|
from .views import ExportModelView, dashboard_summary
|
||||||
from .views_stats import documentos_por_fecha
|
# from .views_stats import documentos_por_fecha
|
||||||
from .views_table import table_summary
|
# from .views_table import table_summary
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('exportmodel/', ExportModelView.as_view(), name='export-model'),
|
path('exportmodel/', ExportModelView.as_view(), name='export-model'),
|
||||||
path('dashboard/summary/', dashboard_summary, name='dashboard-summary'),
|
#path('dashboard/summary/', dashboard_summary, name='dashboard-summary'),
|
||||||
#path('documentos-por-fecha/', documentos_por_fecha, name='documentos-por-fecha'),
|
#path('documentos-por-fecha/', documentos_por_fecha, name='documentos-por-fecha'),
|
||||||
#path('table-summary/', table_summary, name='table-summary'),
|
#path('table-summary/', table_summary, name='table-summary'),
|
||||||
|
|
||||||
|
|||||||
@@ -148,31 +148,6 @@ class ExportModelView(APIView):
|
|||||||
permission_classes = [IsAuthenticated & (
|
permission_classes = [IsAuthenticated & (
|
||||||
IsSameOrganization | IsSameOrganizationAndAdmin | IsSameOrganizationDeveloper | IsSuperUser)]
|
IsSameOrganization | IsSameOrganizationAndAdmin | IsSameOrganizationDeveloper | IsSuperUser)]
|
||||||
|
|
||||||
@swagger_auto_schema(manual_parameters=[openapi.Parameter('model', openapi.IN_QUERY, description="Nombre del modelo (ejemplo: Registro500)",
|
|
||||||
type=openapi.TYPE_STRING, required=True)
|
|
||||||
],
|
|
||||||
responses={200: openapi.Response('Campos disponibles', schema=openapi.Schema(
|
|
||||||
type=openapi.TYPE_OBJECT,
|
|
||||||
properties={
|
|
||||||
'fields': openapi.Schema(type=openapi.TYPE_ARRAY, items=openapi.Items(type=openapi.TYPE_STRING))
|
|
||||||
}
|
|
||||||
))}
|
|
||||||
)
|
|
||||||
def get(self, request, *args, **kwargs):
|
|
||||||
"""
|
|
||||||
Devuelve los campos disponibles para el modelo solicitado.
|
|
||||||
Ejemplo: /api/reports/exportmodel/?model=Registro500
|
|
||||||
"""
|
|
||||||
model_name = request.query_params.get('model')
|
|
||||||
if not model_name:
|
|
||||||
return Response({'error': 'model is required'}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
try:
|
|
||||||
model = apps.get_model('datastage', model_name)
|
|
||||||
except LookupError:
|
|
||||||
return Response({'error': f'Model {model_name} not found'}, status=status.HTTP_404_NOT_FOUND)
|
|
||||||
fields = [f.name for f in model._meta.fields]
|
|
||||||
return Response({'fields': fields})
|
|
||||||
|
|
||||||
@swagger_auto_schema(request_body=ExportModelSerializer, esponses={200: 'Archivo generado (Excel o CSV)'})
|
@swagger_auto_schema(request_body=ExportModelSerializer, esponses={200: 'Archivo generado (Excel o CSV)'})
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
model_name = request.data.get('model')
|
model_name = request.data.get('model')
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
|
||||||
|
from api.logger.mixins import LoggingMixin
|
||||||
from .models import Task
|
from .models import Task
|
||||||
from .serializers import TaskSerializer
|
from .serializers import TaskSerializer
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
from core.permissions import (
|
||||||
|
IsSameOrganization,
|
||||||
|
IsSameOrganizationDeveloper,
|
||||||
|
IsSameOrganizationAndAdmin,
|
||||||
|
IsSuperUser
|
||||||
|
)
|
||||||
|
|
||||||
|
class TaskViewSet(LoggingMixin,viewsets.ModelViewSet):
|
||||||
class TaskViewSet(viewsets.ModelViewSet):
|
permission_classes = [IsAuthenticated & (IsSameOrganization | IsSameOrganizationAndAdmin | IsSameOrganizationDeveloper | IsSuperUser)]
|
||||||
queryset = Task.objects.all()
|
queryset = Task.objects.all()
|
||||||
serializer_class = TaskSerializer
|
serializer_class = TaskSerializer
|
||||||
|
|
||||||
|
my_tags = ['tasks']
|
||||||
Reference in New Issue
Block a user