This repository has been archived by the owner on May 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathconverte_tabela_ibpt.py
74 lines (58 loc) · 1.87 KB
/
converte_tabela_ibpt.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
IBPT_NCM = {}
IBPT_NBS = {}
IBPT_SERVIÇO = {}
class IBPTax(object):
def __init__(self, código='', ex='', al_nacional='0', al_internacional='0'):
self.código = código
self.ex = ex
self.al_nacional = al_nacional
self.al_internacional = al_internacional
self.extras = {}
def cria_análises_ibpt():
f = open('tabelas/IBPTax.0.0.2.csv', 'r', encoding='iso8859-1')
#
# A primeira linha é desprezada porque contém o título das colunas
#
l = f.readline()
for l in f.readlines():
campos = l.split(';')
tipo = campos[2]
ibpt = IBPTax(campos[0], campos[1], campos[4], campos[5])
# NCM
if tipo == '0':
if ibpt.código not in IBPT_NCM:
IBPT_NCM[ibpt.código] = ibpt
IBPT_NCM[ibpt.código].extras[ibpt.ex] = ibpt
else:
if ibpt.ex not in IBPT_NCM[ibpt.código].extras:
IBPT_NCM[ibpt.código].extras[ibpt.ex] = ibpt
elif tipo == '1':
if ibpt.código not in IBPT_NBS:
IBPT_NBS[ibpt.código] = ibpt
else:
print('repetido', l)
elif tipo == '2':
if ibpt.código not in IBPT_SERVIÇO:
IBPT_SERVIÇO[ibpt.código] = ibpt
else:
print('repetido', l)
def ibpt_para_ncm(ncm, ex):
if ncm not in IBPT_NCM:
return IBPTax(código=ncm)
ibpt = IBPT_NCM[ncm]
if ex in ibpt.extras:
return ibpt.extras[ex]
else:
return ibpt
def ibpt_para_nbs(nbs):
if nbs not in IBPT_NBS:
return IBPTax(código=nbs)
else:
return IBPT_NBS[nbs]
def ibpt_para_serviço(serviço):
if serviço not in IBPT_SERVIÇO:
return IBPTax(código=serviço)
else:
return IBPT_SERVIÇO[serviço]