fix/forzar-carga-acuses
This commit is contained in:
@@ -91,12 +91,18 @@ def procesar_coves_pedimento(pedimento_id):
|
||||
"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}")
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/all/coves",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
logging.info(f"COVEs encolados para pedimento {pedimento.pedimento}: {response.json().get('total', '?')}")
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(f"Error encolando COVEs para pedimento {pedimento.pedimento}: {e}")
|
||||
raise
|
||||
|
||||
@shared_task
|
||||
def procesar_acuse_coves_pedimento(pedimento_id):
|
||||
@@ -107,19 +113,25 @@ def procesar_acuse_coves_pedimento(pedimento_id):
|
||||
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}")
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/all/acuse/cove/",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
logging.info(f"Acuses de COVEs encolados para pedimento {pedimento.pedimento}: {response.json().get('total', '?')}")
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(f"Error encolando acuses de COVEs para pedimento {pedimento.pedimento}: {e}")
|
||||
raise
|
||||
|
||||
@shared_task
|
||||
def procesar_edocs_pedimento(pedimento_id):
|
||||
@@ -130,19 +142,25 @@ def procesar_edocs_pedimento(pedimento_id):
|
||||
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/download/all/edocs/",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"}
|
||||
)
|
||||
print(f"Servicio de E-documents enviado para pedimento {pedimento.pedimento}")
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/download/all/edocs/",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
logging.info(f"E-documents encolados para pedimento {pedimento.pedimento}: {response.json().get('total', '?')}")
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(f"Error encolando E-documents para pedimento {pedimento.pedimento}: {e}")
|
||||
raise
|
||||
|
||||
@shared_task
|
||||
def procesar_acuses_pedimento(pedimento_id):
|
||||
@@ -153,19 +171,25 @@ def procesar_acuses_pedimento(pedimento_id):
|
||||
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}")
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/all/acuse/pedimento/",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
logging.info(f"Acuses encolados para pedimento {pedimento.pedimento}: {response.json().get('total', '?')}")
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(f"Error encolando acuses para pedimento {pedimento.pedimento}: {e}")
|
||||
raise
|
||||
|
||||
@shared_task
|
||||
def procesar_partidas_pedimento(pedimento_id):
|
||||
@@ -176,19 +200,32 @@ def procesar_partidas_pedimento(pedimento_id):
|
||||
id=CredencialesImportador.objects.filter(rfc=pedimento.contribuyente).first().vucem.id
|
||||
).first()
|
||||
credenciales_dict = credenciales_to_dict(credenciales)
|
||||
|
||||
|
||||
partidas_pendientes = list(pedimento.partidas.filter(descargado=False))
|
||||
payload = {
|
||||
"partidas": [partida_to_dict(partida) for partida in pedimento.partidas.filter(descargado=False)],
|
||||
"partidas": [partida_to_dict(p) for p in partidas_pendientes],
|
||||
"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}")
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/all/partidas/",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
logging.info(
|
||||
f"Partidas encoladas para pedimento {pedimento.pedimento}: "
|
||||
f"{result.get('total', 0)} de {len(partidas_pendientes)}"
|
||||
)
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(
|
||||
f"Error encolando partidas para pedimento {pedimento.pedimento}: {e}"
|
||||
)
|
||||
raise
|
||||
|
||||
@shared_task
|
||||
def procesar_remesas_pedimento(pedimento_id):
|
||||
@@ -205,12 +242,18 @@ def procesar_remesas_pedimento(pedimento_id):
|
||||
"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}")
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/remesas",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
logging.info(f"Remesa encolada para pedimento {pedimento.pedimento}")
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(f"Error encolando remesa para pedimento {pedimento.pedimento}: {e}")
|
||||
raise
|
||||
|
||||
@shared_task
|
||||
def procesar_pedimento_completo_individual(pedimento_id):
|
||||
@@ -225,13 +268,19 @@ def procesar_pedimento_completo_individual(pedimento_id):
|
||||
"pedimento": pedimento_dict,
|
||||
"credencial": credenciales_dict
|
||||
}
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/pedimento_completo",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"}
|
||||
)
|
||||
print(f"Servicio enviado para pedimento {pedimento.pedimento}")
|
||||
return response
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/pedimento_completo",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
logging.info(f"Pedimento completo encolado: {pedimento.pedimento}")
|
||||
return response
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(f"Error encolando pedimento completo {pedimento.pedimento}: {e}")
|
||||
raise
|
||||
|
||||
@shared_task
|
||||
def procesar_pedimentos_completos(organizacion_id):
|
||||
@@ -270,13 +319,18 @@ def procesar_pedimentos_completos(organizacion_id):
|
||||
url = f"{SERVICE_API_URL_V2}/services/pedimento_completo"
|
||||
dataJson = json.dumps(payload)
|
||||
|
||||
response = requests.post(
|
||||
url,
|
||||
data=dataJson,
|
||||
headers={"Content-Type": "application/json"}
|
||||
)
|
||||
# Aquí puedes continuar con el resto de tu lógica
|
||||
print(f"Servicio enviado para pedimento {pedimento.pedimento}")
|
||||
try:
|
||||
response = requests.post(
|
||||
url,
|
||||
data=dataJson,
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
logging.info(f"Pedimento completo encolado: {pedimento.pedimento}")
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(f"Error encolando pedimento completo {pedimento.pedimento}: {e}")
|
||||
continue
|
||||
|
||||
@shared_task
|
||||
def procesar_remesas(organizacion_id):
|
||||
@@ -311,9 +365,11 @@ def procesar_remesas(organizacion_id):
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/remesas/",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"}
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=60
|
||||
)
|
||||
logger.info(f"Servicio enviado para pedimento {pedimento.pedimento} — status {response.status_code}")
|
||||
response.raise_for_status()
|
||||
logger.info(f"Remesa encolada para pedimento {pedimento.pedimento} — status {response.status_code}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error procesando remesa para pedimento {pedimento.pedimento}: {e}", exc_info=True)
|
||||
@@ -339,14 +395,18 @@ def procesar_coves(organizacion_id):
|
||||
"credencial": credenciales_dict
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/all/coves",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"}
|
||||
)
|
||||
# Aquí puedes continuar con el resto de tu lógica
|
||||
|
||||
print(f"Servicio enviado para pedimento {pedimento.pedimento}")
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/all/coves",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
logging.info(f"COVEs encolados para pedimento {pedimento.pedimento}: {response.json().get('total', '?')}")
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(f"Error encolando COVEs para pedimento {pedimento.pedimento}: {e}")
|
||||
continue
|
||||
|
||||
@shared_task
|
||||
def procesar_acuse_coves(organizacion_id):
|
||||
@@ -370,14 +430,18 @@ def procesar_acuse_coves(organizacion_id):
|
||||
"credencial": credenciales_dict
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/all/acuse/cove/",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"}
|
||||
)
|
||||
# Aquí puedes continuar con el resto de tu lógica
|
||||
|
||||
print(f"Servicio enviado para pedimento {pedimento.pedimento}")
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/all/acuse/cove/",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
logging.info(f"Acuses de COVEs encolados para pedimento {pedimento.pedimento}: {response.json().get('total', '?')}")
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(f"Error encolando acuses de COVEs para pedimento {pedimento.pedimento}: {e}")
|
||||
continue
|
||||
|
||||
@shared_task
|
||||
def procesar_acuses(organizacion_id):
|
||||
@@ -401,14 +465,18 @@ def procesar_acuses(organizacion_id):
|
||||
"credencial": credenciales_dict
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/all/acuse/pedimento/",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"}
|
||||
)
|
||||
# Aquí puedes continuar con el resto de tu lógica
|
||||
|
||||
print(f"Servicio enviado para pedimento {pedimento.pedimento}")
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/all/acuse/pedimento/",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
logging.info(f"Acuses encolados para pedimento {pedimento.pedimento}: {response.json().get('total', '?')}")
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(f"Error encolando acuses para pedimento {pedimento.pedimento}: {e}")
|
||||
continue
|
||||
|
||||
@shared_task
|
||||
def procesar_edocs(organizacion_id):
|
||||
@@ -432,14 +500,18 @@ def procesar_edocs(organizacion_id):
|
||||
"credencial": credenciales_dict
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/download/all/edocs/",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"}
|
||||
)
|
||||
# Aquí puedes continuar con el resto de tu lógica
|
||||
|
||||
print(f"Servicio enviado para pedimento {pedimento.pedimento}")
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/download/all/edocs/",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
logging.info(f"E-documents encolados para pedimento {pedimento.pedimento}: {response.json().get('total', '?')}")
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(f"Error encolando E-documents para pedimento {pedimento.pedimento}: {e}")
|
||||
continue
|
||||
|
||||
@shared_task
|
||||
def procesar_partidas(organizacion_id):
|
||||
@@ -447,29 +519,42 @@ def procesar_partidas(organizacion_id):
|
||||
organizacion_id=organizacion_id,
|
||||
partidas__isnull=False
|
||||
).distinct()
|
||||
|
||||
|
||||
for pedimento in pedimentos:
|
||||
if pedimento.partidas.filter(descargado=False).exists(): # Tipo 4: Partidas
|
||||
# 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()
|
||||
partidas_pendientes = list(pedimento.partidas.filter(descargado=False))
|
||||
if not partidas_pendientes:
|
||||
continue
|
||||
|
||||
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
|
||||
}
|
||||
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(p) for p in partidas_pendientes],
|
||||
"pedimento": pedimento_dict,
|
||||
"credencial": credenciales_dict
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{SERVICE_API_URL_V2}/services/all/partidas/",
|
||||
f"{SERVICE_API_URL_V2}/services/all/partidas/",
|
||||
data=json.dumps(payload),
|
||||
headers={"Content-Type": "application/json"}
|
||||
headers={"Content-Type": "application/json"},
|
||||
timeout=60
|
||||
)
|
||||
# Aquí puedes continuar con el resto de tu lógica
|
||||
|
||||
print(f"Servicio enviado para pedimento {pedimento.pedimento}")
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
logging.info(
|
||||
f"Partidas encoladas para pedimento {pedimento.pedimento}: "
|
||||
f"{result.get('total', 0)} de {len(partidas_pendientes)}"
|
||||
)
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(
|
||||
f"Error encolando partidas para pedimento {pedimento.pedimento}: {e}"
|
||||
)
|
||||
continue
|
||||
|
||||
@shared_task
|
||||
def documentos_con_errores(organizacion_id):
|
||||
|
||||
Reference in New Issue
Block a user