Skip to content

Commit

Permalink
[IMP] soporte para WS de SRI
Browse files Browse the repository at this point in the history
  • Loading branch information
ovnicraft committed Dec 15, 2017
1 parent 5c8e789 commit 280e2c6
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 5 deletions.
6 changes: 5 additions & 1 deletion runa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@
"""

from .api import read_by_nui, busqueda_por_nui # noqa
from .api import ( # noqa
read_by_nui,
busqueda_por_nui,
busqueda_ruc
)
14 changes: 13 additions & 1 deletion runa/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from .utils import (
WS_CIUDADANO,
WS_SRI,
WS_ACCESS,
AUTHORIZED_NUI,
USER,
Expand Down Expand Up @@ -41,7 +42,7 @@ def login(WSDL):

if response.TienePermiso == 'N':
logger.error("No tiene permisos, respuesta de WS: %s" % response.TienePermiso) # noqa
return False
return False, False
return response, client


Expand Down Expand Up @@ -90,3 +91,14 @@ def read_by_nui(nui, mode='prod', authorized_nui=AUTHORIZED_NUI):

def busqueda_por_nui(nui, mode='prod', authorized_nui=AUTHORIZED_NUI):
return read_by_nui(nui, mode=mode, authorized_nui=authorized_nui)


def busqueda_ruc(ruc, AUTHORIZED_NUI=AUTHORIZED_NUI):
response, client = login(WS_SRI)
if not response:
return False
security = create_tokens(response)
client.set_options(security)

consulta_response = client.service.obtenerDatos(numeroRuc=ruc)
print(consulta_response)
59 changes: 57 additions & 2 deletions runa/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,60 @@
logger = logging.getLogger('runa')


class PreparedContribuyente(object):
def __init__(self):
self.numeroRuc = None
self.RUC = None
self.razonSocial = None
self.actividadEconomica = None
self.codClaseContrib = None
self.codEstado = None
self.desClaseContrib = None
self.desEstado = None
self.direccionCorta = None
self.email = None
self.nombreComercial = None
self.telefonoDomicilio = None
self.telefonoTrabajo = None
self.tipoContribuyente = None
self.ubicacionGeografica = None
self.ValidRUC = False

def __repr__(self):
return '<Runa [%s - %s]>' % (self.RUC, self.razonSocial)

def json(self):
return json.dumps(self.__dict__, indent=4)

def is_valid(self):
""" Validate RUC """
try:
import stdnum
except ImportError:
logger.warning("Warning: stdnum library not installed, can't validate.") # noqa
return False
self.ValidRUC = stdnum.ec.ruc.is_valid(self.RUC)
return self.RUC

def prepare(self, response):
self.actividadEconomica = response.actividadEconomica
self.codClaseContrib = response.codClaseContrib
self.codEstado = response.codEstado
self.desClaseContrib = response.desClaseContrib
self.desEstado = response.desEstado
self.direccionCorta = response.direccionCorta
self.email = response.email
self.nombreComercial = response.nombreComercial
self.numeroRuc = response.numeroRuc
self.RUC = response.numeroRuc
self.razonSocial = response.razonSocial
self.telefonoDomicilio = response.telefonoDomicilio
self.telefonoTrabajo = response.telefonoTrabajo
self.tipoContribuyente = response.tipoContribuyente
self.ubicacionGeografica = response.ubicacionGeografica
self.ValidRUC = True


class PreparedRuna(object):

def __init__(self):
Expand Down Expand Up @@ -46,14 +100,15 @@ def __repr__(self):
def json(self):
return json.dumps(self.__dict__, indent=4)

def nui_is_valid(self):
def is_valid(self):
""" Validate NUI """
try:
import stdnum
except ImportError:
logger.warning("Warning: stdnum library not installed, can't validate.") # noqa
return False
return stdnum.ec.ci.is_valid(self.NUI)
self.ValidNUI = stdnum.ec.ci.is_valid(self.NUI)
return self.ValidNUI

def prepare(self, response):
""" Prepare given response data in object"""
Expand Down
1 change: 1 addition & 0 deletions runa/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

AUTHORIZED_NUI = VARS_ENV.get('AUTHORIZED_NUI', None)
WS_CIUDADANO_PRODUCTION = VARS_ENV.get('WS_CIUDADANO_PRODUCTION', None)
WS_SRI = VARS_ENV.get('WS_SRI', None)
WS_CIUDADANO_TESTING = VARS_ENV.get('WS_CIUDADANO_TESTING', None)
WS_ACCESS = VARS_ENV.get('WS_ACCESS', None)
WS_CIUDADANO = WS_CIUDADANO_PRODUCTION
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

requirements = [
'Click>=6.0',
'git+https://github.com/ovnicraft/suds.git'
# TODO: put package requirements here
]

Expand Down

0 comments on commit 280e2c6

Please sign in to comment.