Skip to content

Commit

Permalink
[FIX] RESOLVIENDO LA BUSQUEDA POR RNC (ERROR DE CERIFICADO)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnunezd committed Sep 3, 2024
1 parent 2ceeeb5 commit 550d6cc
Showing 1 changed file with 53 additions and 51 deletions.
104 changes: 53 additions & 51 deletions l10n_do_accounting_plus/models/wsmovildgii.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,64 @@

def get_contribuyentes(self):
rnc = self.vat
data_dict = {}
if rnc:
# Define the SOAP envelope with your request
soap_request = f"""<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetContribuyentes xmlns="http://dgii.gov.do/">
<value>{rnc}</value>
<patronBusqueda>0</patronBusqueda>
<inicioFilas>0</inicioFilas>
<filaFilas>1</filaFilas>
<IMEI></IMEI>
</GetContribuyentes>
</soap12:Body>
</soap12:Envelope>"""

# Define the URL of the SOAP web service
url = "https://dgii.gov.do/wsMovilDGII/WSMovilDGII.asmx?WSDL"

# Define the headers for the SOAP request
headers = {
"Content-Type": "application/soap+xml; charset=utf-8",
}
if len(rnc) not in (9, 11):
warning_message = (f'No es una secuencia valida de Cedula o RNC, puede continuar si no estas validando este '

Check failure on line 12 in l10n_do_accounting_plus/models/wsmovildgii.py

View workflow job for this annotation

GitHub Actions / flake8

line too long (121 > 120 characters)
f'dato de lo contrario verificar {rnc}')
return {'warning': {'title': _('Warning'), 'message': warning_message}}
else:
soap_request = f"""<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetContribuyentes xmlns="http://dgii.gov.do/">
<value>{rnc}</value>
<patronBusqueda>0</patronBusqueda>
<inicioFilas>0</inicioFilas>
<filaFilas>1</filaFilas>
<IMEI></IMEI>
</GetContribuyentes>
</soap12:Body>
</soap12:Envelope>"""

# Make a POST request with the SOAP envelope as the request body
response = requests.post(url, data=soap_request, headers=headers)
url = "https://dgii.gov.do/wsMovilDGII/WSMovilDGII.asmx?WSDL"
headers = {
"Content-Type": "application/soap+xml; charset=utf-8",
}

# Check the status code of the response
if response.status_code == 200:
# Decode the binary response content to a string
response_xml = response.content.decode('utf-8')
response = requests.post(url, data=soap_request, headers=headers, verify=False)

# Parse the XML response
root = ET.fromstring(response_xml)
if response.status_code == 200:
response_xml = response.content.decode('utf-8')
root = ET.fromstring(response_xml)
result_element = root.find('.//{http://dgii.gov.do/}GetContribuyentesResult')

# Find the desired element by its tag name
result_element = root.find('.//{http://dgii.gov.do/}GetContribuyentesResult')
data_dict = json.loads(result_element.text)
if result_element is not None:
try:
data_dict = json.loads(result_element.text)
except json.JSONDecodeError:
warning_message = 'Error en la conexion con la DGII trate un poco mas tarde' % rnc
return {'warning': {'title': _('Warning'), 'message': warning_message}}
else:
print("The desired element was not found in the XML response")

# Check if the element exists
if data_dict:
# Print the text content of the element
if data_dict['ESTATUS'] == "0":
warning_message = 'Este contribuyente se escuentra inativo. \n\nCédula/RNC: %s\nNombre/Razón Social: %s\nEstado: SUSPENDIDO' % (
rnc, data_dict["RGE_NOMBRE"])
return {'warning': {'title': _('Warning'), 'message': warning_message}}
elif data_dict['ESTATUS'] == "2":
self.name = data_dict['RGE_NOMBRE']
elif data_dict['ESTATUS'] == "3":
warning_message = 'Este contribuyente se escuentra Dado de Baja. \n\nCédula/RNC: %s\nNombre/Razón Social: %s\nEstado: DADO DE BAJA' % (
rnc, data_dict["RGE_NOMBRE"])
if data_dict:
if data_dict['ESTATUS'] == "0":
warning_message = ('Este contribuyente se escuentra inativo. \n\nCédula/RNC: %s\nNombre/Razón '
'Social: %s\nEstado: SUSPENDIDO') % (
rnc, data_dict["RGE_NOMBRE"])
return {'warning': {'title': _('Warning'), 'message': warning_message}}
elif data_dict['ESTATUS'] == "2":
self.name = data_dict['RGE_NOMBRE']
elif data_dict['ESTATUS'] == "3":
warning_message = ('Este contribuyente se escuentra Dado de Baja. \n\nCédula/RNC: %s\nNombre/Razón '

Check failure on line 61 in l10n_do_accounting_plus/models/wsmovildgii.py

View workflow job for this annotation

GitHub Actions / flake8

line too long (124 > 120 characters)
'Social: %s\nEstado: DADO DE BAJA') % (
rnc, data_dict["RGE_NOMBRE"])
return {'warning': {'title': _('Warning'), 'message': warning_message}}
else:
warning_message = 'No se encontraron datos registrados de este contribuyente (%s)' % rnc
return {'warning': {'title': _('Warning'), 'message': warning_message}}
else:
warning_message = 'No se encontraron datos registrados de este contribuyente (%s)' % rnc
return {'warning': {'title': _('Warning'), 'message': warning_message}}
else:
# Handle any errors, such as non-200 status codes
print(f"Request failed with status code {response.status_code}")
print(f"Request failed with status code {response.status_code}")

0 comments on commit 550d6cc

Please sign in to comment.