diff --git a/api/api_v2/modules/coves/services.py b/api/api_v2/modules/coves/services.py index 9bcc058..4293381 100644 --- a/api/api_v2/modules/coves/services.py +++ b/api/api_v2/modules/coves/services.py @@ -80,6 +80,14 @@ async def consume_ws_get_cove(**kwargs): raise Exception("No se recibió respuesta del servicio SOAP") if soap_error(soap_response): + document_response = await coves_rest_controller.post_document( + soap_response=soap_response, + organizacion=kwargs.get('pedimento').get('organizacion'), + pedimento=kwargs.get('pedimento').get('id'), + file_name=f"vu_COVE_{pedimento_app}_{cove}_ERROR.xml", + document_type=10, + ) + raise Exception("Error en la respuesta del servicio SOAP") logger.info("Respuesta SOAP exitosa, enviando documento") @@ -87,23 +95,14 @@ async def consume_ws_get_cove(**kwargs): # Enviar documento _file_name = f"vu_COVE_{pedimento_app}_{cove}.xml" try: - if soap_error(soap_response): - document_response = await coves_rest_controller.post_document( - soap_response=soap_response, - organizacion=kwargs.get('pedimento').get('organizacion'), - pedimento=kwargs.get('pedimento').get('id'), - file_name=f"vu_COVE_{pedimento_app}_{cove}_ERROR.xml", - document_type=10, - ) - raise Exception("Error en la respuesta del servicio SOAP") - else: - document_response = await coves_rest_controller.post_document( - soap_response=soap_response, - organizacion=kwargs.get('pedimento').get('organizacion'), - pedimento=kwargs.get('pedimento').get('id'), - file_name=_file_name, - document_type=8, - ) + + document_response = await coves_rest_controller.post_document( + soap_response=soap_response, + organizacion=kwargs.get('pedimento').get('organizacion'), + pedimento=kwargs.get('pedimento').get('id'), + file_name=_file_name, + document_type=8, + ) except Exception as e: logger.error(f"Error detectado en la respuesta SOAP: {str(e)}") raise Exception(f"Error en la respuesta SOAP: {str(e)}") diff --git a/api/api_v2/modules/partidas/services.py b/api/api_v2/modules/partidas/services.py index 4318c93..14013e5 100644 --- a/api/api_v2/modules/partidas/services.py +++ b/api/api_v2/modules/partidas/services.py @@ -70,6 +70,13 @@ async def consume_ws_get_partida(**kwargs): raise Exception("No se recibió respuesta del servicio SOAP") if soap_error(soap_response): + document_response = await partida_rest_controller.post_document( + soap_response=soap_response, + organizacion=kwargs.get('pedimento').get('organizacion'), + pedimento=kwargs.get('pedimento').get('id'), + file_name=f"vu_PT_{pedimento_app}_{partida.get('numero', '')}_ERROR.xml", + document_type=10, + ) raise Exception("Error en la respuesta del servicio SOAP") logger.info("Respuesta SOAP exitosa, enviando documento") @@ -77,23 +84,14 @@ async def consume_ws_get_partida(**kwargs): # Enviar documento _file_name = f"vu_PT_{pedimento_app}_{partida.get('numero', '')}.xml" try: - if soap_error(soap_response): - document_response = await partida_rest_controller.post_document( - soap_response=soap_response, - organizacion=kwargs.get('pedimento').get('organizacion'), - pedimento=kwargs.get('pedimento').get('id'), - file_name=f"vu_PT_{pedimento_app}_{partida.get('numero', '')}_ERROR.xml", - document_type=10, - ) - raise Exception("Error en la respuesta del servicio SOAP") - else: - document_response = await partida_rest_controller.post_document( - soap_response=soap_response, - organizacion=kwargs.get('pedimento').get('organizacion'), - pedimento=kwargs.get('pedimento').get('id'), - file_name=_file_name, - document_type=1, - ) + + document_response = await partida_rest_controller.post_document( + soap_response=soap_response, + organizacion=kwargs.get('pedimento').get('organizacion'), + pedimento=kwargs.get('pedimento').get('id'), + file_name=_file_name, + document_type=1, + ) except Exception as e: logger.error(f"Error detectado en la respuesta SOAP: {str(e)}") diff --git a/api/api_v2/modules/pedimentos/services.py b/api/api_v2/modules/pedimentos/services.py index c8a20a3..8705e80 100644 --- a/api/api_v2/modules/pedimentos/services.py +++ b/api/api_v2/modules/pedimentos/services.py @@ -74,6 +74,13 @@ async def consume_ws_get_pedimento_completo(**kwargs) -> Dict[str, Any]: if soap_error(soap_response): 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") # Extraer datos del XML @@ -88,23 +95,13 @@ async def consume_ws_get_pedimento_completo(**kwargs) -> Dict[str, Any]: # Enviar documento 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( - soap_response=soap_response, - organizacion=pedimento_data.get('organizacion'), - pedimento=pedimento_data.get('id'), - file_name=file_name, - document_type=2, - ) + document_response = await pedimento_rest_controller.post_document( + soap_response=soap_response, + organizacion=pedimento_data.get('organizacion'), + pedimento=pedimento_data.get('id'), + file_name=file_name, + document_type=2, + ) except Exception as e: logger.error(f"Error al enviar documento: {e}") raise HTTPException(status_code=500, detail="Error al guardar documento") diff --git a/api/api_v2/modules/remesas/services.py b/api/api_v2/modules/remesas/services.py index 4e076c0..f6b3c8a 100644 --- a/api/api_v2/modules/remesas/services.py +++ b/api/api_v2/modules/remesas/services.py @@ -69,34 +69,18 @@ async def obtener_remesa(**kwargs) -> Dict[str, Any]: data=soap_xml, 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 file_name = f"vu_RM_{pedimento_data.get('pedimento_app', 'unknown')}.xml" # Enviar documento try: 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( - soap_response=None, + soap_response=soap_response, organizacion=pedimento_data.get('organizacion'), 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, ) raise HTTPException(status_code=500, detail="Error en la respuesta del servicio SOAP") @@ -108,11 +92,20 @@ async def obtener_remesa(**kwargs) -> Dict[str, Any]: file_name=file_name, document_type=3, ) + except Exception as e: logger.error(f"Error al enviar documento: {e}") 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')}") return {