This commit is contained in:
2025-10-05 17:33:54 -06:00
parent cf181023bd
commit 8b151a6fe9
4 changed files with 57 additions and 70 deletions

View File

@@ -79,14 +79,6 @@ async def consume_ws_get_cove(**kwargs):
if not soap_response: if not soap_response:
raise Exception("No se recibió respuesta del servicio SOAP") raise Exception("No se recibió respuesta del servicio SOAP")
if soap_error(soap_response):
raise Exception("Error en la respuesta del servicio SOAP")
logger.info("Respuesta SOAP exitosa, enviando documento")
# Enviar documento
_file_name = f"vu_COVE_{pedimento_app}_{cove}.xml"
try:
if soap_error(soap_response): if soap_error(soap_response):
document_response = await coves_rest_controller.post_document( document_response = await coves_rest_controller.post_document(
soap_response=soap_response, soap_response=soap_response,
@@ -95,8 +87,15 @@ async def consume_ws_get_cove(**kwargs):
file_name=f"vu_COVE_{pedimento_app}_{cove}_ERROR.xml", file_name=f"vu_COVE_{pedimento_app}_{cove}_ERROR.xml",
document_type=10, document_type=10,
) )
raise Exception("Error en la respuesta del servicio SOAP") raise Exception("Error en la respuesta del servicio SOAP")
else:
logger.info("Respuesta SOAP exitosa, enviando documento")
# Enviar documento
_file_name = f"vu_COVE_{pedimento_app}_{cove}.xml"
try:
document_response = await coves_rest_controller.post_document( document_response = await coves_rest_controller.post_document(
soap_response=soap_response, soap_response=soap_response,
organizacion=kwargs.get('pedimento').get('organizacion'), organizacion=kwargs.get('pedimento').get('organizacion'),

View File

@@ -69,14 +69,6 @@ async def consume_ws_get_partida(**kwargs):
if not soap_response: if not soap_response:
raise Exception("No se recibió respuesta del servicio SOAP") raise Exception("No se recibió respuesta del servicio SOAP")
if soap_error(soap_response):
raise Exception("Error en la respuesta del servicio SOAP")
logger.info("Respuesta SOAP exitosa, enviando documento")
# Enviar documento
_file_name = f"vu_PT_{pedimento_app}_{partida.get('numero', '')}.xml"
try:
if soap_error(soap_response): if soap_error(soap_response):
document_response = await partida_rest_controller.post_document( document_response = await partida_rest_controller.post_document(
soap_response=soap_response, soap_response=soap_response,
@@ -86,7 +78,13 @@ async def consume_ws_get_partida(**kwargs):
document_type=10, document_type=10,
) )
raise Exception("Error en la respuesta del servicio SOAP") raise Exception("Error en la respuesta del servicio SOAP")
else:
logger.info("Respuesta SOAP exitosa, enviando documento")
# Enviar documento
_file_name = f"vu_PT_{pedimento_app}_{partida.get('numero', '')}.xml"
try:
document_response = await partida_rest_controller.post_document( document_response = await partida_rest_controller.post_document(
soap_response=soap_response, soap_response=soap_response,
organizacion=kwargs.get('pedimento').get('organizacion'), organizacion=kwargs.get('pedimento').get('organizacion'),

View File

@@ -74,6 +74,13 @@ async def consume_ws_get_pedimento_completo(**kwargs) -> Dict[str, Any]:
if soap_error(soap_response): if soap_error(soap_response):
logger.error(f"Error en respuesta SOAP: {soap_response.text if hasattr(soap_response, 'text') else 'Sin detalles'}") logger.error(f"Error en respuesta SOAP: {soap_response.text if hasattr(soap_response, 'text') else 'Sin detalles'}")
document_response = await pedimento_rest_controller.post_document(
soap_response=None,
organizacion=pedimento_data.get('organizacion'),
pedimento=pedimento_data.get('id'),
file_name=f"vu_PC_{pedimento_data.get('pedimento_app', 'unknown')}_ERROR.xml",
document_type=10,
)
raise HTTPException(status_code=500, detail="Error en la respuesta del servicio SOAP") raise HTTPException(status_code=500, detail="Error en la respuesta del servicio SOAP")
# Extraer datos del XML # Extraer datos del XML
@@ -88,16 +95,6 @@ async def consume_ws_get_pedimento_completo(**kwargs) -> Dict[str, Any]:
# Enviar documento # Enviar documento
try: try:
if soap_error(soap_response):
document_response = await pedimento_rest_controller.post_document(
soap_response=None,
organizacion=pedimento_data.get('organizacion'),
pedimento=pedimento_data.get('id'),
file_name=f"vu_PC_{pedimento_data.get('pedimento_app', 'unknown')}_ERROR.xml",
document_type=10,
)
raise HTTPException(status_code=500, detail="Error en la respuesta del servicio SOAP")
else:
document_response = await pedimento_rest_controller.post_document( document_response = await pedimento_rest_controller.post_document(
soap_response=soap_response, soap_response=soap_response,
organizacion=pedimento_data.get('organizacion'), organizacion=pedimento_data.get('organizacion'),

View File

@@ -69,34 +69,18 @@ async def obtener_remesa(**kwargs) -> Dict[str, Any]:
data=soap_xml, data=soap_xml,
headers=soap_headers headers=soap_headers
) )
if not soap_response:
raise HTTPException(status_code=500, detail="No se recibió respuesta del servicio SOAP")
if soap_error(soap_response):
logger.error(f"Error en respuesta SOAP: {soap_response.text if hasattr(soap_response, 'text') else 'Sin detalles'}")
raise HTTPException(status_code=500, detail="Error en la respuesta del servicio SOAP")
# Extraer datos del XML
try:
remesas_data = remesa_xml_scraper.extract_remesas(soap_response.text)
except Exception as e:
logger.error(f"Error al extraer datos XML: {e}")
raise HTTPException(status_code=500, detail="Error al procesar respuesta XML")
# Generar nombre de archivo # Generar nombre de archivo
file_name = f"vu_RM_{pedimento_data.get('pedimento_app', 'unknown')}.xml" file_name = f"vu_RM_{pedimento_data.get('pedimento_app', 'unknown')}.xml"
# Enviar documento # Enviar documento
try: try:
if soap_error(soap_response): if soap_error(soap_response):
file_name = f"vu_RM_{pedimento_data.get('pedimento_app', 'unknown')}.xml"
document_response = await remesa_rest_controller.post_document( document_response = await remesa_rest_controller.post_document(
soap_response=None, soap_response=soap_response,
organizacion=pedimento_data.get('organizacion'), organizacion=pedimento_data.get('organizacion'),
pedimento=pedimento_data.get('id'), pedimento=pedimento_data.get('id'),
file_name=f"vu_RM_{pedimento_data.get('pedimento_app', 'unknown')}_ERROR.xml", file_name=file_name,
document_type=10, document_type=10,
) )
raise HTTPException(status_code=500, detail="Error en la respuesta del servicio SOAP") raise HTTPException(status_code=500, detail="Error en la respuesta del servicio SOAP")
@@ -108,10 +92,19 @@ async def obtener_remesa(**kwargs) -> Dict[str, Any]:
file_name=file_name, file_name=file_name,
document_type=3, document_type=3,
) )
except Exception as e: except Exception as e:
logger.error(f"Error al enviar documento: {e}") logger.error(f"Error al enviar documento: {e}")
raise HTTPException(status_code=500, detail="Error al guardar documento") raise HTTPException(status_code=500, detail="Error al guardar documento")
# Extraer datos del XML
try:
remesas_data = remesa_xml_scraper.extract_remesas(soap_response.text)
except Exception as e:
logger.error(f"Error al extraer datos XML: {e}")
raise HTTPException(status_code=500, detail="Error al procesar respuesta XML")
logger.info(f"Remesa procesada exitosamente: {pedimento_data.get('pedimento')}") logger.info(f"Remesa procesada exitosamente: {pedimento_data.get('pedimento')}")