import os
import form
import ocupacoes
+import declaracoes
class OcupacaoForm(form.OptionsForm):
def __init__(self, ocupacoes, contribuinte):
irpf_dir.get_userdata_dir())
self.cpf_file = irpf_dir.get_userdata_file("%s/%s.xml" % (self.cpf, self.cpf))
- self.iddecl_file = irpf_dir.get_userdata_file("iddeclaracoes.xml")
- self.declaracao = self._find_id()
+ ncpf = self._normalize_cpf(self.cpf)
+ self.declaracao = declaracoes.Declaracoes().find("cpf", ncpf)
self.dados = xml.dom.minidom.parse(self.cpf_file)
self.contribuinte = self.dados.getElementsByTagName("contribuinte")[0]
- def _find_id(self):
- cpf = self._normalize_cpf(self.cpf)
- self.declaracoes = xml.dom.minidom.parse(self.iddecl_file)
- for i in self.declaracoes.getElementsByTagName("item"):
- if "cpf" in i.attributes.keys():
- if i.attributes["cpf"].nodeValue == cpf:
- return i
- return None
-
# CPF normalizado se parece com 000.000.000-00
def _normalize_cpf(self, cpf):
ncpf = ""
def save(self):
self.dados.writexml(open(self.cpf_file, "w"))
- self.declaracoes.writexml(open(self.iddecl_file, "w"))
+ self.declaracao.save()
def _get_attr(self, el, attr):
if attr in el.attributes.keys():
el.attributes[attr].nodeValue = val
def get_declaracao(self, attr):
- return self._get_attr(self.declaracao, attr)
+ return self.declaracao.get_attr(attr)
def set_declaracao(self, attr, val):
- self._set_attr(self.declaracao, attr, val)
+ self.declaracao.set_attr(attr, val)
def get_nome(self):
return self.get_declaracao("nome")
ocup = ocupacoes.Ocupacoes()
form.append(ContribuinteForm("Nome", "nome", self))
form.append(OcupacaoForm(ocup, self))
- for i in contribuinte_attributes:
+ for i in self.attributes:
form.append(ContribuinteForm(i, i, self))
return form
-contribuinte_attributes = [
- "nome",
- "dataNascimento",
- "tituloEleitor",
- "doencaDeficiencia",
- "exterior",
- "pais",
- "cep",
- "uf",
- "cidade",
- "municipio",
- "tipoLogradouro",
- "logradouro",
- "numero",
- "complemento",
- "bairro",
- "bairroExt",
- "cepExt",
- "logradouroExt",
- "numeroExt",
- "complementoExt",
- "ocupacaoPrincipal",
- "codigoExterior",
- "ddd",
- "telefone",
- "naturezaOcupacao",
- ]
-
-declaracao_attributes = [
- "dataUltimoAcesso",
- "declaracaoRetificadora",
- "enderecoDiferente",
- "enderecoMACRede",
- "exercicio",
- "nome",
- "numReciboDecRetif",
- "numeroReciboDecAnterior",
- "resultadoDeclaracao",
- "tipoDeclaracao",
- "tipoDeclaracaoAES",
- "transmitida",
- "versaoBeta"
- ]
+ attributes = [
+ "nome",
+ "dataNascimento",
+ "tituloEleitor",
+ "doencaDeficiencia",
+ "exterior",
+ "pais",
+ "cep",
+ "uf",
+ "cidade",
+ "municipio",
+ "tipoLogradouro",
+ "logradouro",
+ "numero",
+ "complemento",
+ "bairro",
+ "bairroExt",
+ "cepExt",
+ "logradouroExt",
+ "numeroExt",
+ "complementoExt",
+ "ocupacaoPrincipal",
+ "codigoExterior",
+ "ddd",
+ "telefone",
+ "naturezaOcupacao",
+ ]
if __name__ == '__main__':
import sys
print ("Campo " + campo + " retornou vazio")
else:
print "\nCONTRIBUINTE:"
- for i in contribuinte_attributes:
+ for i in Contribuinte.attributes:
val = contribuinte.get_campo_contribuinte(i)
if val == None:
val = ""
print i + ": " + val
print "\nDECLARACAO:"
- for i in declaracao_attributes:
+ for i in declaracoes.Declaracoes.attributes:
val = contribuinte.get_declaracao(i)
if val == None:
val = ""
--- /dev/null
+# coding=utf-8
+#
+# Copyright 2013-2014 Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# -*- mode: python; encoding: utf-8; -*-
+
+import xml.dom.minidom
+import dirs
+import os
+import items
+
+class Declaracoes(items.Items):
+ def __init__(self):
+ irpf_dir = dirs.get_default_irpf_dir()
+
+ if not os.path.exists(irpf_dir.get_resource_dir()):
+ raise RuntimeError("O caminho para o resource não existe: " + \
+ irpf_dir.get_resource_dir())
+
+ if not os.path.exists(irpf_dir.get_userdata_dir()):
+ raise RuntimeError("O caminho para os dados não existe: " + \
+ irpf_dir.get_userdata_dir())
+
+ self.iddecl_file = irpf_dir.get_userdata_file("iddeclaracoes.xml")
+ self.declaracoes = xml.dom.minidom.parse(self.iddecl_file)
+ classe = self.declaracoes.getElementsByTagName("classe")[0]
+ items.Items.__init__(self, classe)
+
+ def save(self):
+ self.declaracoes.writexml(open(self.iddecl_file, "w"))
+
+ attributes = [
+ "dataUltimoAcesso",
+ "declaracaoRetificadora",
+ "enderecoDiferente",
+ "enderecoMACRede",
+ "exercicio",
+ "nome",
+ "numReciboDecRetif",
+ "numeroReciboDecAnterior",
+ "resultadoDeclaracao",
+ "tipoDeclaracao",
+ "tipoDeclaracaoAES",
+ "transmitida",
+ "versaoBeta"
+ ]
+
+if __name__ == '__main__':
+ import sys
+ dec = Declaracoes()
+
+ for i in dec.items:
+ print i.get_attr("cpf") + " " + i.get_attr("nome")
+
+# vim:tabstop=4:expandtab:smartindent