Adicionar formulário para Declaracoes.
[cascardo/irpf-gui.git] / src / declaracoes.py
1 # coding=utf-8
2 #
3 #   Copyright 2013-2014 Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
4 #
5 #   This program is free software: you can redistribute it and/or modify
6 #   it under the terms of the GNU General Public License as published by
7 #   the Free Software Foundation, either version 3 of the License, or
8 #   (at your option) any later version.
9 #
10 #   This program is distributed in the hope that it will be useful,
11 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #   GNU General Public License for more details.
14 #
15 #   You should have received a copy of the GNU General Public License
16 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 # -*- mode: python; encoding: utf-8; -*-
18
19 import xml.dom.minidom
20 import dirs
21 import os
22 import items
23 import form
24
25 class Declaracoes(items.Items):
26     def __init__(self):
27         irpf_dir = dirs.get_default_irpf_dir()
28
29         if not os.path.exists(irpf_dir.get_resource_dir()):
30             raise RuntimeError("O caminho para o resource não existe: " + \
31                     irpf_dir.get_resource_dir())
32
33         if not os.path.exists(irpf_dir.get_userdata_dir()):
34             raise RuntimeError("O caminho para os dados não existe: " + \
35                     irpf_dir.get_userdata_dir())
36
37         self.iddecl_file = irpf_dir.get_userdata_file("iddeclaracoes.xml")
38         self.declaracoes = xml.dom.minidom.parse(self.iddecl_file)
39         classe = self.declaracoes.getElementsByTagName("classe")[0]
40         items.Items.__init__(self, classe)
41
42     def form(self, item):
43         f = []
44         for i in self.attributes:
45             f.append(form.AttrForm(i, i, item))
46         return f
47
48     def save(self):
49         self.declaracoes.writexml(open(self.iddecl_file, "w"))
50
51     attributes = [
52             "dataUltimoAcesso",
53             "declaracaoRetificadora",
54             "enderecoDiferente",
55             "enderecoMACRede",
56             "exercicio",
57             "nome",
58             "numReciboDecRetif",
59             "numeroReciboDecAnterior",
60             "resultadoDeclaracao",
61             "tipoDeclaracao",
62             "tipoDeclaracaoAES",
63             "transmitida",
64             "versaoBeta"
65             ]
66
67 if __name__ == '__main__':
68     import sys
69     dec = Declaracoes()
70
71     for i in dec.items:
72         print i.get_attr("cpf") + " " + i.get_attr("nome")
73
74 # vim:tabstop=4:expandtab:smartindent