forked from jonathanf/gdimm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwndMain.py
340 lines (252 loc) · 11.4 KB
/
wndMain.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
import sys, os
import ezGlade
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
import gtk.glade
except:
sys.exit(1)
from data import *
from ref_data import RefData
import configuration
from wndDeclaracion import wndDeclaracion
from wndContribuyente import wndContribuyente
from utils import *
ezGlade.set_file(configuration.GLADE_FILE)
class wndAcerca(ezGlade.BaseWindow):
def on_wndAcerca_close(self, *args):
self.win.destroy()
def on_wndAcerca_response(self, *args):
self.win.destroy()
class wndMain(ezGlade.BaseWindow):
lista_contribuyentes = None
declaracion = None
ref_data = None
def load_contribuyentes(self):
"Carga el combobox con la lista de contribuyentes e incluye la opción de editar"
self.lista_contribuyentes.clear()
self.lista_contribuyentes.append(['','Editar lista de contribuyentes...'])
lstContribuyentes = ListaContribuyentes()
lstContribuyentes.load()
for item in lstContribuyentes.get_elements():
self.lista_contribuyentes.append([item.get_ruc(), item.get_nombre()])
def post_init(self):
self.ref_data = RefData()
self.declaracion = Declaracion()
self.lista_contribuyentes = gtk.ListStore(str, str)
self.load_contribuyentes()
self.cmbContribuyente.set_model(self.lista_contribuyentes)
self.cmbContribuyente.clear()
cell_ruc = gtk.CellRendererText()
cell_nombre = gtk.CellRendererText()
self.cmbContribuyente.pack_start(cell_nombre, False)
self.cmbContribuyente.pack_end(cell_ruc, False)
self.cmbContribuyente.add_attribute(cell_ruc, 'text', 0)
self.cmbContribuyente.add_attribute(cell_nombre, 'text', 1)
#Combo para el manejo de formularios
self.cmbFormularios.clear()
list_store = gtk.ListStore(str, str)
self.cmbFormularios.set_model(list_store)
lista_datos = self.ref_data.get_datos_formularios()
for code, name in lista_datos:
list_store.append([name, code])
cell_formulario = gtk.CellRendererText()
self.cmbFormularios.pack_start(cell_formulario, False)
self.cmbFormularios.add_attribute(cell_formulario, 'text', 0)
self.cmbFormularios.set_active(0)
# combo de anios
self.cmbAnio.clear()
list_store = gtk.ListStore(str, str)
self.cmbAnio.set_model(list_store)
lista_datos = self.ref_data.get_data_list(30) # anios
lista_datos.reverse()
for code, name in lista_datos:
list_store.append([name, code])
cell_anios = gtk.CellRendererText()
self.cmbAnio.pack_start(cell_anios, False)
self.cmbAnio.add_attribute(cell_anios, 'text', 0)
self.cmbAnio.set_active(0)
def destroy(self, *args):
gtk.main_quit()
def on_btnAbout_clicked(self, *args):
vAcercaDe = wndAcerca()
vAcercaDe.set_parent(self)
vAcercaDe.set_modal(True)
vAcercaDe.show()
def on_cmbContribuyente_changed(self, widget, *args):
"Señal que se dispara cuando se cambia la selección de un contribuyente de la lista"
iter = widget.get_active_iter()
if not iter:
return # Para cortar el proceso cuando se vuelva a disparar el evento al desmarcar el item actualmente seleccionado
codigo_contribuyente = self.lista_contribuyentes.get_value(iter, 0)
if codigo_contribuyente == "":
widget.set_active(-1) #Hace que se deseleccione el item del combobox
frmContribuyentes = wndContribuyente()
frmContribuyentes.set_parent(self)
frmContribuyentes.set_modal(True)
frmContribuyentes.show()
else:
lstContribuyentes = ListaContribuyentes() # TODO cargar una sola vez?
lstContribuyentes.load()
contribuyente = lstContribuyentes.find_by_ruc(codigo_contribuyente)
if contribuyente is not None:
self.declaracion.set_contribuyente(contribuyente)
def on_btnNuevaDeclaracion_clicked(self, *args):
self.swMain.show()
def on_btnEditar_clicked(self, *args):
self.swMain.hide()
dialog = gtk.FileChooserDialog("Abrir...", self.win, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
dialog.set_current_folder(os.path.join('XML_Declaraciones'))
filter = gtk.FileFilter()
filter.set_name("Archivos XML")
filter.add_mime_type("application/xml")
filter.add_pattern("*.xml")
dialog.add_filter(filter)
response = dialog.run()
if response == gtk.RESPONSE_OK:
filename = dialog.get_filename() # archivo
parser = etree.XMLParser(remove_comments=True, encoding='utf8')
xml = etree.parse(filename, parser)
dialog.destroy()
else:
dialog.destroy()
return
lstContribuyentes = ListaContribuyentes() # TODO cargar una sola vez?
lstContribuyentes.load()
self.declaracion = Declaracion()
try:
self.declaracion = self.declaracion.cargar_declaracion_guardada(xml, lstContribuyentes, self.ref_data)
self.declaracion.set_archivo(filename)
except Exception as ex:
ezGlade.DialogBox(str(ex), 'error', self.win)
return
# crear ventana del formulario de declaracion
vDeclaracion = wndDeclaracion()
vDeclaracion.set_declaracion(self.declaracion)
vDeclaracion.load_widgets_from_xml()
vDeclaracion.update_container_from_xml(xml)
vDeclaracion.push_statusbar_info(filename)
vDeclaracion.show()
def on_btnHelp_clicked(self, *args):
ezGlade.DialogBox("Abrir archivo de ayuda en HTML", "info")
def on_btnClose_clicked(self, *args):
"Botón que cierra la pantalla principal y termina la aplicación"
gtk.main_quit()
sys.exit(0)
def on_rbSustitutiva_toggled(self, widget, *args):
if widget.get_active() :
self.hbSustituye.show()
else:
self.hbSustituye.hide()
def on_rbSemestral_toggled(self, widget, *args):
version = get_active_text(self.cmbFormularios)
nombre = self.ref_data.get_nombre_formulario(version)
self.cmbPeriodo.clear()
list_store = gtk.ListStore(str, str)
self.cmbPeriodo.set_model(list_store)
lista_datos = []
if widget.get_active() :
lista_datos = self.ref_data.get_data_list(40) # periodos
self.declaracion.set_periodicidad("SEMESTRAL")
codigo_version = self.ref_data.get_codigo_version_formulario(nombre, "SEMESTRAL")
else:
lista_datos = self.ref_data.get_data_list(20) # meses
self.declaracion.set_periodicidad("MENSUAL")
codigo_version = self.ref_data.get_codigo_version_formulario(nombre, "MENSUAL")
self.declaracion.set_version(version)
self.declaracion.set_codigo_version(codigo_version)
for code, name in lista_datos:
list_store.append([name, code])
cell_periodo = gtk.CellRendererText()
self.cmbPeriodo.pack_start(cell_periodo, False)
self.cmbPeriodo.add_attribute(cell_periodo, 'text', 0)
self.cmbPeriodo.set_active(0)
self.vbPeriodo.show()
def on_cmbFormularios_changed(self, widget, *args):
version = get_active_text(widget)
nombre = self.ref_data.get_nombre_formulario(version)
self.cmbPeriodo.clear()
list_store = gtk.ListStore(str, str)
self.cmbPeriodo.set_model(list_store)
lista_datos = []
periodicidad = self.ref_data.get_periodicidad(version)
if periodicidad == "MENSUAL_SEMESTRAL":
self.hbPeriodo.show()
if self.rbSemestral.get_active() :
lista_datos = self.ref_data.get_data_list(40) # periodos
self.declaracion.set_periodicidad("SEMESTRAL")
codigo_version = self.ref_data.get_codigo_version_formulario(nombre, "SEMESTRAL")
else:
lista_datos = self.ref_data.get_data_list(20) # meses
self.declaracion.set_periodicidad("MENSUAL")
codigo_version = self.ref_data.get_codigo_version_formulario(nombre, "MENSUAL")
elif periodicidad == "MENSUAL":
self.hbPeriodo.hide()
lista_datos = self.ref_data.get_data_list(20) # meses
self.declaracion.set_periodicidad("MENSUAL")
codigo_version = self.ref_data.get_codigo_version_formulario(nombre, "MENSUAL")
else:
self.declaracion.set_periodicidad("ANUAL")
codigo_version = self.ref_data.get_codigo_version_formulario(nombre, "ANUAL")
self.declaracion.set_version(version)
self.declaracion.set_codigo_version(codigo_version)
for code, name in lista_datos:
list_store.append([name, code])
cell_periodo = gtk.CellRendererText()
self.cmbPeriodo.pack_start(cell_periodo, False)
self.cmbPeriodo.add_attribute(cell_periodo, 'text', 0)
self.cmbPeriodo.set_active(0)
self.vbPeriodo.show()
def on_btnAceptar_clicked(self, *args):
# contribuyente
if self.declaracion.get_contribuyente() is None:
ezGlade.DialogBox("No se ha seleccionado el contribuyente", "error")
return
# alias del formulario
version = get_active_text(self.cmbFormularios)
alias = self.ref_data.get_nombre_formulario(version)
alias = alias.replace("FORMULARIO ", "")
self.declaracion.set_alias_formulario(alias)
# archivo nulo
self.declaracion.set_archivo(None)
# obtener anio
anio = get_active_text(self.cmbAnio)
self.declaracion.set_anio(anio)
# obtener mes o periodo
periodo = get_active_text(self.cmbPeriodo)
self.declaracion.set_mes(periodo)
# original o sustitutiva
if self.rbSustitutiva.get_active():
self.declaracion.set_original('S')
self.declaracion.set_sustituye(self.txtSustituye.get_text())
else:
self.declaracion.set_original('O')
self.declaracion.set_sustituye('')
# crear ventana del formulario de declaracion
vDeclaracion = wndDeclaracion()
vDeclaracion.set_declaracion(self.declaracion)
vDeclaracion.load_widgets_from_xml()
vDeclaracion.push_statusbar_info("Nueva declaración")
vDeclaracion.show()