Skip to content

Commit b76b4df

Browse files
committed
WIP: download zip file
1 parent d731741 commit b76b4df

4 files changed

+22
-6
lines changed

som_switching/demo/som_switching_demo_data.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
<field name="ref2">R1-003</field>
3131
</record>
3232
</data>
33-
</openerp>
33+
</openerp>

som_switching/tests/tests_wizard_reexport_log.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
from destral import testing
43
from destral.transaction import Transaction
54
from giscedata_switching.tests.common_tests import TestSwitchingImport
65

som_switching/wizard/giscedata_switching_log_reexport_wizard.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def reexport_files(self, cursor, uid, ids, context=None):
1818
context = {}
1919
if not isinstance(ids, list):
2020
ids = [ids]
21+
wizard = self.browse(cursor, uid, ids[0], context=context)
2122
log_ids = context.get('active_ids', False)
2223

2324
if not log_ids:
@@ -32,6 +33,7 @@ def reexport_files(self, cursor, uid, ids, context=None):
3233
})
3334
failed_files = []
3435
log_vals = log_obj.read(cursor, uid, log_ids, ['status', 'pas', 'proces', 'request_code'])
36+
generated_files = []
3537
for log in log_vals:
3638
if log['status'] == 'correcte':
3739
continue
@@ -43,7 +45,9 @@ def reexport_files(self, cursor, uid, ids, context=None):
4345
try:
4446
step_id = step_obj.search(cursor, uid,
4547
[('name', '=', log['pas']), ('proces_id', '=', proces_id[0])])
46-
sw_obj.exportar_xml(cursor, uid, sw_id[0], step_id[0], pas_id[0], context=context)
48+
xml = sw_obj.exportar_xml(
49+
cursor, uid, sw_id[0], step_id[0], pas_id[0], context=context)
50+
generated_files.append(xml)
4751
except Exception, e:
4852
e_string = str(e)
4953
if not e_string:
@@ -54,12 +58,23 @@ def reexport_files(self, cursor, uid, ids, context=None):
5458
info += _(u"S'han produït els següents errors en els arxius exportats:\n")
5559
for failed_f in failed_files:
5660
info += _(u"\t- Fitxer {} -> Error: {}\n".format(failed_f[0], failed_f[1]))
57-
58-
self.write(cursor, uid, ids, {'state': 'end', 'msg': info}, context=context)
61+
fileHandle = StringIO.StringIO()
62+
zf = zipfile.ZipFile(fileHandle, mode='w', compression=comp)
63+
nom_zip = 'casos_exportats.zip'
64+
for file in generated_files:
65+
zf.writestr(file[0], file[1])
66+
zf.close()
67+
wizard.write({
68+
'report': base64.encodestring(fileHandle.getvalue()),
69+
'filename': nom_zip,
70+
})
71+
wizard.write({'state': 'end', 'msg': info}, context=context)
5972

6073
_columns = {
6174
'state': fields.selection([('init', 'Init'), ('end', 'End')], 'State'),
62-
'msg': fields.text('Missatge')
75+
'msg': fields.text('Missatge'),
76+
'report': fields.binary('Fichero a descargar'),
77+
'filename': fields.char('Nombre fichero exportado', size=256),
6378
}
6479

6580
_defaults = {

som_switching/wizard/giscedata_switching_log_reexport_wizard_view.xml

+2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
<field name="arch" type="xml">
99
<form string="Reexportar fitxers dels logs">
1010
<field name="state" invisible="1"/>
11+
<field name="filename" invisible="1"/>
1112
<field name="msg" nolabel="1" readonly="1" height="200" width="600"/>
1213
<group col="2" colspan="8" attrs="{'invisible': [('state', '!=', 'init')]}">
1314
<button string="Cancel·lar" special="cancel" icon="gtk-close" colspan="1"/>
1415
<button string="Reexportar fitxers" name="reexport_files" type="object" icon="gtk-go-forward" colspan="1" />
1516
</group>
1617
<group col="2" colspan="8" attrs="{'invisible': [('state', '=', 'init')]}">
18+
<field name="report" width="500" filename="filename_report"/>
1719
<button string="Tancar" special="cancel" icon="gtk-close" colspan="1"/>
1820
</group>
1921
</form>

0 commit comments

Comments
 (0)