T2026-05-030
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# auditoria_xml.py
|
||||
import xml.etree.ElementTree as ET
|
||||
from datetime import datetime
|
||||
import logging
|
||||
logger = logging.getLogger('api.customs.auditoria_xml')
|
||||
|
||||
def extraer_info_pedimento_xml(xml_content):
|
||||
"""
|
||||
@@ -13,8 +15,10 @@ def extraer_info_pedimento_xml(xml_content):
|
||||
# Buscar el namespace (puede variar)
|
||||
namespaces = {
|
||||
'S': 'http://schemas.xmlsoap.org/soap/envelope/',
|
||||
's': 'http://schemas.xmlsoap.org/soap/envelope/',
|
||||
'ns2': 'http://www.ventanillaunica.gob.mx/pedimentos/ws/oxml/consultarpedimentocompleto',
|
||||
'ns3': 'http://www.ventanillaunica.gob.mx/common/ws/oxml/respuesta'
|
||||
'ns3': 'http://www.ventanillaunica.gob.mx/common/ws/oxml/respuesta',
|
||||
|
||||
}
|
||||
|
||||
resultado = {}
|
||||
@@ -181,10 +185,37 @@ def extraer_info_pedimento_xml(xml_content):
|
||||
if edocs_encontrados:
|
||||
resultado['edocuments_en_xml'] = edocs_encontrados
|
||||
|
||||
# Verificar si hay error en la respuesta
|
||||
# Verificar si hay error en la respuesta — 3 variantes según el servicio VUCEM:
|
||||
# 1) Remesas/pedimentos: <ns3:tieneError> en namespace oxml/respuesta
|
||||
# 2) eDocuments: <TieneError> en namespace tempuri.org, mensaje en <Errores>
|
||||
# 3) Acuses: <error> sin namespace dentro de responseConsultaAcuses
|
||||
tiene_error = root.find('.//ns3:tieneError', namespaces)
|
||||
if tiene_error is not None:
|
||||
resultado['tiene_error'] = tiene_error.text.lower() == 'true'
|
||||
if resultado['tiene_error']:
|
||||
mensaje = root.find('.//ns3:error/ns3:mensaje', namespaces)
|
||||
if mensaje is not None and mensaje.text:
|
||||
resultado['error_mensaje'] = mensaje.text.strip()
|
||||
else:
|
||||
# Variante eDocuments (tempuri.org)
|
||||
tiene_error_edoc = root.find('.//{http://tempuri.org/}TieneError')
|
||||
if tiene_error_edoc is not None:
|
||||
resultado['tiene_error'] = tiene_error_edoc.text.lower() == 'true'
|
||||
if resultado['tiene_error']:
|
||||
errores_elem = root.find('.//{http://tempuri.org/}Errores')
|
||||
if errores_elem is not None and errores_elem.text:
|
||||
resultado['error_mensaje'] = errores_elem.text.strip()
|
||||
else:
|
||||
# Variante acuses: <error> sin namespace
|
||||
error_acuses = root.find('.//error')
|
||||
if error_acuses is not None and error_acuses.text is not None:
|
||||
resultado['tiene_error'] = error_acuses.text.lower() == 'true'
|
||||
if resultado['tiene_error']:
|
||||
descripciones = root.findall('.//mensajeErrores/descripcion')
|
||||
if descripciones:
|
||||
resultado['error_mensaje'] = ' | '.join(
|
||||
d.text.strip() for d in descripciones if d.text
|
||||
)
|
||||
|
||||
return resultado
|
||||
|
||||
|
||||
Reference in New Issue
Block a user