Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requeriments.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coveralls==0.5
six==1.9.0
pytest==2.6.4
Unidecode==1.0.22
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def run_tests(self):
'Programming Language :: Python :: 3.4',
],
keywords='sped fiscal contábil contabilidade receita federal',
install_requires=['six'],
install_requires=['six', 'Unidecode'],
tests_require=['pytest'],
cmdclass={'test': PyTest},
)
6 changes: 3 additions & 3 deletions sped/arquivos.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from collections import OrderedDict
from io import StringIO

from .registros import RegistroIndefinido
from sped.efd.icms_ipi.registros import Registro0000, Registro9999


class ArquivoDigital(object):
registros = None
blocos = None

registro_abertura = RegistroIndefinido
registro_fechamento = RegistroIndefinido
registro_abertura = Registro0000
registro_fechamento = Registro9999

def __init__(self):
self._registro_abertura = self.registro_abertura()
Expand Down
36 changes: 33 additions & 3 deletions sped/campos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@


import re

from datetime import date
from datetime import datetime
from decimal import Decimal

from six import string_types
from unidecode import unidecode

from .erros import CampoFixoError
from .erros import CampoObrigatorioError
Expand Down Expand Up @@ -102,16 +102,26 @@ def set(self, registro, valor):


class CampoAlfanumerico(Campo):
def __init__(self, indice, nome, obrigatorio=False, tamanho=255):
def __init__(self, indice, nome, obrigatorio=False, tamanho=255, somente_numeros=False, zfill=False, upper=True):
super(CampoAlfanumerico, self).__init__(indice, nome, obrigatorio)
self._tamanho = tamanho

self._somente_numeros = somente_numeros
self._zill = zfill
self._upper = upper
@property
def tamanho(self):
return self._tamanho

def set(self, registro, valor):
valor = valor or ''
if isinstance(valor, string_types):
valor = unidecode(valor)
if self._somente_numeros:
valor = re.sub('[\D]', '', valor)
if self._zill:
valor = valor.zfill(self._tamanho)
if self._upper:
valor = valor.upper()
valor = valor[:self._tamanho]
super(CampoAlfanumerico, self).set(registro, valor)

Expand Down Expand Up @@ -184,9 +194,21 @@ def set(self, registro, valor):
raise FormatoInvalidoError(registro, self.nome)


class CampoInteiro(Campo):

@staticmethod
def validar(valor):
return valor.isdigit()

def set(self, registro, valor):
super(CampoInteiro, self).set(registro, str(valor))


class CampoCNPJ(Campo):

@staticmethod
def validar(valor):
valor = re.sub('[\D]', '', valor)
if len(valor) != 14:
return False

Expand All @@ -210,10 +232,14 @@ def validar(valor):

return True

def set(self, registro, valor):
super(CampoCNPJ, self).set(registro, re.sub('[\D]', '', valor or ''))


class CampoCPF(Campo):
@staticmethod
def validar(valor):
valor = re.sub('[\D]', '', valor)
if len(valor) != 11:
return False

Expand All @@ -237,10 +263,14 @@ def validar(valor):

return True

def set(self, registro, valor):
super(CampoCPF, self).set(registro, re.sub('[\D]', '', valor or ''))


class CampoCPFouCNPJ(Campo):
@staticmethod
def validar(valor):
valor = re.sub('[\D]', '', valor)
if len(valor) == 14:
return CampoCNPJ.validar(valor)
if len(valor) == 11:
Expand Down
Loading