

def validate_cuit(cuit):
    "from: http://python.org.ar/pyar/Recetario/ValidarCuit by Mariano Reingart"
    # validaciones minimas
    if len(cuit) != 13 or cuit[2] != "-" or cuit [11] != "-":
        return False

    base = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2]

    cuit = cuit.replace("-", "")

    # calculo digito verificador
    aux = 0
    for i in range(10):
        aux += int(cuit[i]*base[i])

    aux = 11 - (aux - (int(aux/11) * 11))

    if aux == 11:
        aux = 0
    if aux == 10:
        aux = 9

    return aux == int(cuit[10])

import re

def validate_cuit(cuit):
    """
    Validates CUIT (Argentina) - Clave Única de Identificación Triebutaria
    from: http://python.org.ar/pyar/Recetario/ValidarCuit by Mariano Reingart
    """
    cuit = str(cuit).replace("-", "") # normalize
    # validaciones minimas
    if not re.match(r'\d{11}$', cuit):
        return False

    base = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2]

    # calculo digito verificador
    aux = sum([int(cuit[i])*base[i] for i in range(10)])
    aux = 11 - (aux % 11)

    if aux == 11:
        aux = 0
    if aux == 10:
        aux = 9

    return aux == int(cuit[10])


def validate_cbu(cbu):
    "Validates CBU (Argentina) - Clave Bancaria Uniforme"
    cbu = str(cbu).replace(" ", "") # normalize
    # validaciones minimas
    if not re.match(r'\d{22}$', cbu):
        return False

    # calculo digito verificador banco
    base = [7, 1, 3, 9, 7, 1, 3]
    aux = sum([int(cbu[i])*base[i] for i in range(7)])

    if (10 - (aux % 10)) != int(cbu[7]):
        return False

    # calculo digito verificador cuenta
    base = [3, 9, 7, 1, 3, 9, 7, 1, 3, 9, 7, 1, 3]
    aux = sum([int(cbu[i+8])*base[i] for i in range(13)])

    return (10 - (aux % 10)) == int(cbu[21])

Add cbu validator to utils module
Add cbu validator to utils module

- 
+ import re
  
  def validate_cuit(cuit):
+     """
+     Validates CUIT (Argentina) - Clave Única de Identificación Triebutaria
-     "from: http://python.org.ar/pyar/Recetario/ValidarCuit by Mariano Reingart"
+     from: http://python.org.ar/pyar/Recetario/ValidarCuit by Mariano Reingart
+     """
+     cuit = str(cuit).replace("-", "") # normalize
      # validaciones minimas
-     if len(cuit) != 13 or cuit[2] != "-" or cuit [11] != "-":
+     if not re.match(r'\d{11}$', cuit):
          return False
  
      base = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2]
  
-     cuit = cuit.replace("-", "")
- 
      # calculo digito verificador
+     aux = sum([int(cuit[i])*base[i] for i in range(10)])
+     aux = 11 - (aux % 11)
-     aux = 0
-     for i in range(10):
-         aux += int(cuit[i]*base[i])
- 
-     aux = 11 - (aux - (int(aux/11) * 11))
  
      if aux == 11:
          aux = 0
      if aux == 10:
          aux = 9
  
      return aux == int(cuit[10])
  
+ 
+ def validate_cbu(cbu):
+     "Validates CBU (Argentina) - Clave Bancaria Uniforme"
+     cbu = str(cbu).replace(" ", "") # normalize
+     # validaciones minimas
+     if not re.match(r'\d{22}$', cbu):
+         return False
+ 
+     # calculo digito verificador banco
+     base = [7, 1, 3, 9, 7, 1, 3]
+     aux = sum([int(cbu[i])*base[i] for i in range(7)])
+ 
+     if (10 - (aux % 10)) != int(cbu[7]):
+         return False
+ 
+     # calculo digito verificador cuenta
+     base = [3, 9, 7, 1, 3, 9, 7, 1, 3, 9, 7, 1, 3]
+     aux = sum([int(cbu[i+8])*base[i] for i in range(13)])
+ 
+     return (10 - (aux % 10)) == int(cbu[21])
+ 
Add cbu validator to utils module
## Code Before:


def validate_cuit(cuit):
    "from: http://python.org.ar/pyar/Recetario/ValidarCuit by Mariano Reingart"
    # validaciones minimas
    if len(cuit) != 13 or cuit[2] != "-" or cuit [11] != "-":
        return False

    base = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2]

    cuit = cuit.replace("-", "")

    # calculo digito verificador
    aux = 0
    for i in range(10):
        aux += int(cuit[i]*base[i])

    aux = 11 - (aux - (int(aux/11) * 11))

    if aux == 11:
        aux = 0
    if aux == 10:
        aux = 9

    return aux == int(cuit[10])

## Instruction:
Add cbu validator to utils module
## Code After:
import re

def validate_cuit(cuit):
    """
    Validates CUIT (Argentina) - Clave Única de Identificación Triebutaria
    from: http://python.org.ar/pyar/Recetario/ValidarCuit by Mariano Reingart
    """
    cuit = str(cuit).replace("-", "") # normalize
    # validaciones minimas
    if not re.match(r'\d{11}$', cuit):
        return False

    base = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2]

    # calculo digito verificador
    aux = sum([int(cuit[i])*base[i] for i in range(10)])
    aux = 11 - (aux % 11)

    if aux == 11:
        aux = 0
    if aux == 10:
        aux = 9

    return aux == int(cuit[10])


def validate_cbu(cbu):
    "Validates CBU (Argentina) - Clave Bancaria Uniforme"
    cbu = str(cbu).replace(" ", "") # normalize
    # validaciones minimas
    if not re.match(r'\d{22}$', cbu):
        return False

    # calculo digito verificador banco
    base = [7, 1, 3, 9, 7, 1, 3]
    aux = sum([int(cbu[i])*base[i] for i in range(7)])

    if (10 - (aux % 10)) != int(cbu[7]):
        return False

    # calculo digito verificador cuenta
    base = [3, 9, 7, 1, 3, 9, 7, 1, 3, 9, 7, 1, 3]
    aux = sum([int(cbu[i+8])*base[i] for i in range(13)])

    return (10 - (aux % 10)) == int(cbu[21])
