|
| 1 | +# -*- encoding: utf-8 -*- |
| 2 | +import base64 |
| 3 | + |
| 4 | +from osv import osv, fields |
| 5 | +from tools.translate import _ |
| 6 | + |
| 7 | + |
| 8 | +class WizardReexportLogAttachment(osv.osv_memory): |
| 9 | + _name = 'wizard.giscedata.switching.log.reexport' |
| 10 | + |
| 11 | + def _get_default_msg(self, cursor, uid, context=None): |
| 12 | + if context is None: |
| 13 | + context = {} |
| 14 | + log_ids = context.get('active_ids', []) |
| 15 | + return _(u"Es reexportaràn {} arxius".format(len(log_ids))) |
| 16 | + |
| 17 | + def reexport_files(self, cursor, uid, ids, context=None): |
| 18 | + if context is None: |
| 19 | + context = {} |
| 20 | + |
| 21 | + log_ids = context.get('active_ids', False) |
| 22 | + |
| 23 | + if not log_ids: |
| 24 | + raise osv.except_osv('Error', _('No s\'han seleccionat ids')) |
| 25 | + log_obj = self.pool.get('giscedata.switching.log') |
| 26 | + attach_obj = self.pool.get('ir.attachment') |
| 27 | + sw_obj = self.pool.get('giscedata.switching') |
| 28 | + step_obj = self.pool.get('giscedata.switching.step') |
| 29 | + proces_obj = self.pool.get('giscedata.switching.proces') |
| 30 | + |
| 31 | + context.update({ |
| 32 | + 'update_logs': True |
| 33 | + }) |
| 34 | + failed_files = [] |
| 35 | + log_vals = log_obj.read(cursor, uid, log_ids, ['status', 'pas', 'proces', 'request_code']) |
| 36 | + for log in log_vals: |
| 37 | + if log['status'] == 'correcte': |
| 38 | + continue |
| 39 | + sw_id = sw_obj.search([('codi_sollicitud', '=', log_vals['request_code'])]) |
| 40 | + proces_id = proces.obj.search([('name', '=', log_vals['proces'])]) |
| 41 | + pas_obj = self.pool.get('giscedata.switching.{}.{}'.format( |
| 42 | + log_vals['proces'], log_vals['pas'])) |
| 43 | + pas_id = pas_obj.search([('sw_id', '=', sw_id)]) |
| 44 | + try: |
| 45 | + step_id = step_obj.search( |
| 46 | + [('name', '=', log_vals['pas']), ('proces_id', '=', proces_id[0])]) |
| 47 | + sw_obj.exportar_xml(cursor, uid, sw_id[0], step_id[0], pas_id[0], context=context) |
| 48 | + except Exception, e: |
| 49 | + e_string = str(e) |
| 50 | + if not e_string: |
| 51 | + e_string = e.value |
| 52 | + failed_files.append((fname, e_string)) |
| 53 | + info = _(u"S'han processat {} fitxers.\n".format(len(log_vals))) |
| 54 | + if failed_files: |
| 55 | + info += _(u"S'han produït els següents errors en els arxius exportats:\n") |
| 56 | + for failed_f in failed_files: |
| 57 | + info += _(u"\t- Fitxer {} -> Error: {}\n".format(failed_f[0], failed_f[1])) |
| 58 | + |
| 59 | + self.write(cursor, uid, ids, {'state': 'end', 'msg': info}, context=context) |
| 60 | + |
| 61 | + _columns = { |
| 62 | + 'state': fields.selection([('init', 'Init'), ('end', 'End')], 'State'), |
| 63 | + 'msg': fields.text('Missatge') |
| 64 | + } |
| 65 | + |
| 66 | + _defaults = { |
| 67 | + 'state': lambda *a: 'init', |
| 68 | + 'msg': _get_default_msg, |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | +WizardReexportLogAttachment() |
0 commit comments