Posted By

eliluminado on 02/16/12


Tagged

cuit


Versions (?)

esCUITValida


 / Published in: Python
 

URL: https://github.com/eliluminado/esCUITValida

Aplicacion en Python para verificar la valides de la CUIT

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # <Aplicacion en Python para verificar la valides de la CUIT.>
  5. # Copyright (C) 2012 Alejandro Alvarez <[email protected]>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. # http://www.codigopython.com.ar <[email protected]>
  21.  
  22. def esCUITValida(cuit):
  23. """
  24. Funcion destinada a la validacion de CUIT
  25. """
  26. # Convertimos el valor a una cadena
  27. cuit = str(cuit)
  28. # Aca se ve si es de la forma de 13 caracteres
  29. # con los guiones
  30. if len(cuit) == 13 and cuit[2] == '-' and cuit[11] == '-':
  31. # Removemos los guiones para trabajar
  32. cuit = cuit.replace('-', '')
  33. # Si no tiene 11 caracteres lo descartamos
  34. elif len(cuit) != 11:
  35. return False, cuit
  36. # Solo resta analizar si todos los caracteres son numeros
  37. if not cuit.isdigit():
  38. return False, cuit
  39. # Despues de estas validaciones podemos afirmar
  40. # que contamos con 11 numeros
  41. base = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2]
  42. aux = 0
  43. for i in xrange(10):
  44. aux += int(cuit[i]) * base[i]
  45. aux = 11 - (aux % 11)
  46. if aux == 11:
  47. aux = 0
  48. elif aux == 10:
  49. aux = 9
  50. if int(cuit[10]) == aux:
  51. return True, cuit
  52. else:
  53. return False, cuit

Report this snippet  

You need to login to post a comment.