forked from sped-br/python-sped
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy patharquivos.py
More file actions
75 lines (64 loc) · 2.55 KB
/
arquivos.py
File metadata and controls
75 lines (64 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
from .. import arquivos
from . import blocos
from . import registros
from .blocos import Bloco0
from .blocos import BlocoI
from .blocos import BlocoJ
from .blocos import Bloco9
from .registros import Registro0000
from .registros import Registro9900
from .registros import Registro9999
from .registros import RegistroI030
from .registros import RegistroJ900
class ArquivoDigital(arquivos.ArquivoDigital):
registro_abertura = Registro0000
registro_encerramento = Registro9999
registros = registros
blocos = blocos
def __init__(self):
super(ArquivoDigital, self).__init__()
self._blocos['0'] = Bloco0('0')
self._blocos['I'] = BlocoI('I')
self._blocos['J'] = BlocoJ('J')
self._blocos['9'] = Bloco9('9')
def prepare(self):
bloco_9 = self._blocos['9'] = Bloco9('9')
for bloco in self._blocos.values():
regs = {}
for reg in bloco.registros:
if reg.REG not in regs:
regs[reg.REG] = 0
regs[reg.REG] += 1
if bloco == self._blocos['0']:
bloco.registro_encerramento.QTD_LIN_0 = sum(
[x for x in regs.values()]) + 1
regs['0000'] = 1
if bloco == self._blocos['I']:
bloco.registro_encerramento.QTD_LIN_I = sum(
[x for x in regs.values()])
if bloco == self._blocos['J']:
bloco.registro_encerramento.QTD_LIN_J = sum(
[x for x in regs.values()])
if bloco == bloco_9:
regs['9999'] = 1
regs['9900'] += len(regs.keys())
for reg in regs.keys():
registro = Registro9900()
registro.REG_BLC = reg
registro.QTD_REG_BLC = regs[reg]
bloco_9.add(registro)
if bloco == self._blocos['9']:
bloco.registro_encerramento.QTD_LIN_9 = sum(
[x for x in regs.values()])
reg_count = 2
for bloco in self._blocos.values():
reg_count += len(bloco.registros)
encerramentoI = [x for x in self._blocos['I'].registros
if isinstance(x, RegistroI030)]
encerramentoI[0].QTD_LIN = reg_count
encerramentoJ = [x for x in self._blocos['J'].registros
if isinstance(x, RegistroJ900)]
encerramentoJ[0].QTD_LIN = reg_count
# self._blocos['J'].registros[1].QTD_LIN = reg_count
self._registro_encerramento.QTD_LIN = reg_count