@@ -18,6 +18,7 @@ def reexport_files(self, cursor, uid, ids, context=None):
18
18
context = {}
19
19
if not isinstance (ids , list ):
20
20
ids = [ids ]
21
+ wizard = self .browse (cursor , uid , ids [0 ], context = context )
21
22
log_ids = context .get ('active_ids' , False )
22
23
23
24
if not log_ids :
@@ -32,6 +33,7 @@ def reexport_files(self, cursor, uid, ids, context=None):
32
33
})
33
34
failed_files = []
34
35
log_vals = log_obj .read (cursor , uid , log_ids , ['status' , 'pas' , 'proces' , 'request_code' ])
36
+ generated_files = []
35
37
for log in log_vals :
36
38
if log ['status' ] == 'correcte' :
37
39
continue
@@ -43,7 +45,9 @@ def reexport_files(self, cursor, uid, ids, context=None):
43
45
try :
44
46
step_id = step_obj .search (cursor , uid ,
45
47
[('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 )
47
51
except Exception , e :
48
52
e_string = str (e )
49
53
if not e_string :
@@ -54,12 +58,23 @@ def reexport_files(self, cursor, uid, ids, context=None):
54
58
info += _ (u"S'han produït els següents errors en els arxius exportats:\n " )
55
59
for failed_f in failed_files :
56
60
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 )
59
72
60
73
_columns = {
61
74
'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 ),
63
78
}
64
79
65
80
_defaults = {
0 commit comments