Introduz classe tipos para ocupações, tipo de bens, etc.
authorThadeu Lima de Souza Cascardo <cascardo@cascardo.info>
Sun, 23 Mar 2014 19:29:00 +0000 (16:29 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.info>
Sun, 23 Mar 2014 19:29:00 +0000 (16:29 -0300)
src/tipos.py [new file with mode: 0644]

diff --git a/src/tipos.py b/src/tipos.py
new file mode 100644 (file)
index 0000000..c236554
--- /dev/null
@@ -0,0 +1,62 @@
+# coding=utf-8
+#
+#   Copyright 2013 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
+
+class Tipos:
+    def __init__(self, fname, cols, group = -1):
+        irpf_dir = dirs.get_default_irpf_dir()
+        self.xml = xml.dom.minidom.parse(irpf_dir.get_resource_file(fname))
+        self.l = []
+        self.g = {}
+        self.cols = cols
+        self.group = group
+        self._list()
+        if group >= 0:
+            self._group()
+
+    def _list(self):
+        for i in self.xml.getElementsByTagName("ITEM"):
+            if self.cols[-1] in i.attributes.keys():
+                item = []
+                for j in self.cols:
+                    item.append(i.attributes[j].nodeValue)
+                self.l.append(item)
+
+    def list(self):
+        return self.l
+
+    def _group(self):
+        for i in self.l:
+            if i[self.group] not in self.g:
+                self.g[i[self.group]] = []
+            self.g[i[self.group]].append(i)
+
+    def groups(self):
+        if group < 0:
+            return None
+        return self.g
+
+    def get_by_code(self, code):
+        for i in self.l:
+            if i[0] == code:
+                return i
+        return None
+
+# vim:tabstop=4:expandtab:smartindent