Skip to content
This repository was archived by the owner on Nov 2, 2024. It is now read-only.

Commit 65fceca

Browse files
Commit Inicial
0 parents  commit 65fceca

31 files changed

Lines changed: 5269 additions & 0 deletions

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.{py,rst,ini}]
12+
indent_style = space
13+
indent_size = 4
14+
15+
[*.{yml,html,css,js}]
16+
indent_style = space
17+
indent_size = 2

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Basics
2+
*.py[cod]
3+
*.pyc
4+
__pycache__
5+
6+
# Logs
7+
*.log
8+
pip-log.txt
9+
10+
# Unit test / coverage reports
11+
.coverage
12+
.tox
13+
nosetests.xml
14+
15+
# Translations
16+
*.mo
17+
*.pot
18+
19+
# Pycharm
20+
.idea
21+
22+
# Vim
23+
24+
*~
25+
*.swp
26+
*.swo
27+
28+
# npm
29+
node_modules/
30+
31+
# Compass
32+
.sass-cache
33+
34+
# Vagrant
35+
.vagrant
36+
37+
# Generated files
38+
assets/
39+
40+
# Setup Generated files
41+
dist
42+
*.egg-info

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 SPED-BR (https://github.com/sped-br) e seus contribuidores
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# python-sped
2+
3+
Biblioteca para geração dos arquivos do Sistema Público de Escrituração Digital (SPED) para Python 3.4+.
4+
5+
This software is coded and documented in portuguese only as it is intended to be used to generate the necessary files for the brazilian government regarding to digital bookkeeping.
6+
7+
## Como instalar
8+
9+
pip install sped
10+
11+
## Objetivos do Projeto
12+
13+
A ideia inicial do projeto e unificar em uma única biblioteca módulos para facilitar a geração dos arquivos do SPED, diminuido o retrabalho necessário para isso e tentando ao máximo garantir que o arquivo gerado seja considerado válido pelo validador do SPED.
14+
15+
Não é objetivo deste projeto, remover a necessidade do programador em conhecer o SPED, bem como sua legislação e saber informar adequadamente todas as informações corretamente.
16+
17+
## Compatibilidade do Projeto
18+
19+
O projeto inicialmente suportará apenas Python 3.4+, devido a minha necessidade de integra-lo ao meu sistema ERP. Em breve e se houver tempo e necessidade, poderei auxiliar a portabilidade para Python 2.7 para facilitar seu uso no OpenERP. Pull requests que adicionem compatibilidade são bem vindos.
20+
21+
Outras linguagens de programação poderão ter versões especificas conforme minha disponibilidade de tempo.
22+
23+
## Contribuições para o Projeto
24+
25+
Contribuições são bem vindas ao projeto, exemplos de como você pode contribuir:
26+
* usando o projeto e [apontando bugs](https://github.com/sped-br/python-sped/issues)
27+
* [sugestões de melhoria](https://github.com/sped-br/python-sped/issues)
28+
* enviando [pull requests](https://github.com/sped-br/python-sped/pulls)
29+
* auxiliando na [documentação](https://github.com/sped-br/python-sped/wiki)
30+
31+
## Status do Projeto
32+
33+
O projeto está em fase inicial de desenvolvimento e não deve ser usado em produção.
34+
35+
| Módulo | Status |
36+
|----------------|:-------------:|
37+
| ECD | Não Iniciado |
38+
| ECF | Iniciado |
39+
| EFD-PIS/COFINS | Funcional |
40+
| EFD-ICMS/IPI | Não Iniciado |
41+
42+
### ECD
43+
44+
Este módulo ainda não foi iniciado seu desenvolvimento.
45+
46+
### ECF
47+
48+
Este módulo está em fase inicial de desenvolvimento, seu registros ainda não estão com os campos populados.
49+
50+
### EFD-PIS/COFINS
51+
52+
Este módulo está funcional, com todos seus registros codificados, porém muitos campos ainda não possuem uma validação
53+
adequada, consultado tabelas externas por exemplo, ou validando corretamente todos os tamanhos de campos.
54+
55+
Ele pode ser usado para gerar um arquivo digital, com validações de abertura e fechamento de bloco automaticamente.
56+
57+
### EFD-ICMS/IPI
58+
59+
Este módulo ainda não foi iniciado seu desenvolvimento.

doctest_runner.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if __name__ == "__main__":
2+
import doctest
3+
4+
from sped import campos
5+
from sped import erros
6+
from sped import registros
7+
8+
doctest.testmod(campos)
9+
doctest.testmod(erros)
10+
doctest.testmod(registros)

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[metadata]
2+
description-file = README.md

setup.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from setuptools import setup, find_packages
2+
from sped import __version__
3+
4+
setup(
5+
name='sped',
6+
packages=find_packages(exclude=['contrib', 'docs', 'tests*']),
7+
version=__version__,
8+
description='Biblioteca para geração dos arquivos do Sistema Público de Escrituração Digital (SPED) para Python.',
9+
author='Sergio Garcia',
10+
author_email='sergio@ginx.com.br',
11+
url='https://github.com/sped-br/python-sped',
12+
license='MIT',
13+
classifiers=[
14+
'Development Status :: 3 - Alpha',
15+
'Intended Audience :: Developers',
16+
'License :: OSI Approved :: MIT License',
17+
'Programming Language :: Python :: 3',
18+
'Programming Language :: Python :: 3.4',
19+
],
20+
keywords='sped fiscal contábil contabilidade receita federal',
21+
)

sped/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = '0.1'

sped/arquivos.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from collections import OrderedDict
2+
from io import StringIO
3+
4+
5+
class ArquivoDigital(object):
6+
registro_abertura = None
7+
registro_fechamento = None
8+
registros = None
9+
blocos = None
10+
11+
def __init__(self):
12+
self._registro_abertura = self.__class__.registro_abertura()
13+
self._registro_fechamento = self.__class__.registro_fechamento()
14+
self._blocos = OrderedDict()
15+
16+
def readfile(self, filename):
17+
with open(filename) as file:
18+
for line in [line.rstrip('\r\n') for line in file]:
19+
self.read_registro(line)
20+
21+
def read_registro(self, line):
22+
reg_id = line.split('|')[1]
23+
24+
try:
25+
registro_class = getattr(self.__class__.registros, 'Registro' + reg_id)
26+
except AttributeError:
27+
raise RuntimeError("Arquivo inválido para EFD - PIS/COFINS")
28+
29+
registro = registro_class(line)
30+
31+
if registro.__class__ == self.__class__.registro_abertura:
32+
self._registro_abertura = registro
33+
elif registro.__class__ == self.__class__.registro_fechamento:
34+
self._registro_fechamento = registro
35+
else:
36+
bloco_id = reg_id[0]
37+
bloco = self._blocos[bloco_id]
38+
bloco.add(registro)
39+
40+
def write_to(self, buffer):
41+
buffer.write(self._registro_abertura.as_line() + '\r\n')
42+
for key in self._blocos.keys():
43+
bloco = self._blocos[key]
44+
for r in bloco.registros:
45+
buffer.write(r.as_line() + '\r\n')
46+
buffer.write(self._registro_fechamento.as_line() + '\r\n')
47+
48+
def getstring(self):
49+
buffer = StringIO()
50+
self.write_to(buffer)
51+
return buffer.getvalue()

0 commit comments

Comments
 (0)