Skip to content

Commit 1a85b01

Browse files
committed
WIP
1 parent fa0592d commit 1a85b01

6 files changed

+163
-3
lines changed

som_switching/__terp__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
'wizard/wizard_create_atc_from_polissa.xml',
4545
'giscedata_atc_view.xml',
4646
'wizard/giscedata_switching_wizard_b1.xml',
47-
'wizard/wizard_close_obsolete_cases.xml',
47+
'wizard/wizard_close_obsolete_cases.xml'
48+
'wizard/giscedata_switching_log_reexport_wizard_view.xml',
49+
4850
],
4951
"active": False,
5052
"installable": True

som_switching/tests/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
from tests_wizard_switching_b1 import *
99
from tests_wizard_import_atr_and_f1 import *
1010
from tests_unlink_atc import *
11-
from tests_wizard_validate_d101 import *
11+
from tests_wizard_validate_d101 import *
12+
from tests_wizard_reexport_log import *
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from destral import testing
4+
from destral.transaction import Transaction
5+
6+
7+
class TestWizardReexportLog(testing.OOTestCase):
8+
9+
def setUp(self):
10+
self.txn = Transaction().start(self.database)
11+
self.cursor = self.txn.cursor
12+
self.uid = self.txn.user
13+
self.pool = self.openerp.pool
14+
self.wiz_o = self.pool.get('wizard.giscedata.switching.log.reimport')
15+
16+
def tearDown(self):
17+
self.txn.stop()
18+
19+
def test_create_c1_01(self):
20+
with Transaction().start(self.database) as txn:
21+
self.switch(txn, 'comer', other_id_name='res_partner_asus')
22+
uid = txn.user
23+
cursor = txn.cursor
24+
25+
contract_id = self.get_contract_id(txn)
26+
self.activar_polissa_CUPS(txn)
27+
28+
step_id = self.create_case_and_step(
29+
cursor, uid, contract_id, 'C1', '01'
30+
)
31+
32+
step_obj = self.openerp.pool.get('giscedata.switching.c1.01')
33+
sw_obj = self.openerp.pool.get('giscedata.switching')
34+
35+
c101 = step_obj.browse(cursor, uid, step_id)
36+
c1 = sw_obj.browse(cursor, uid, c101.sw_id.id)
37+
38+
self.assertEqual(c1.proces_id.name, 'C1')
39+
self.assertEqual(c1.step_id.name, '01')
40+
self.assertEqual(c1.cups_id.name, 'ES1234000000000001JN0F')
41+
self.assertEqual(len(c101.telefons), 1)
42+
self.assertEqual(c101.telefons[0].numero, '935555555')
43+
self.assertEqual(c101.contratacion_incondicional_bs, 'N')
44+
self.assertFalse(c101.bono_social)

som_switching/wizard/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
import giscedata_switching_wizard_b1
1111
import wizard_import_atr_and_f1
1212
import wizard_close_obsolete_cases
13-
import wizard_validate_d101
13+
import wizard_validate_d101
14+
import giscedata_switching_log_reexport_wizard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<openerp>
3+
<data>
4+
<record id="view_wizard_giscedata_switching_log_reexport_form" model="ir.ui.view">
5+
<field name="name">wizard.giscedata.switching.log.reexport.form</field>
6+
<field name="model">wizard.giscedata.switching.log.reexport</field>
7+
<field name="type">form</field>
8+
<field name="arch" type="xml">
9+
<form string="Reexportar fitxers dels logs">
10+
<field name="state" invisible="1"/>
11+
<field name="msg" nolabel="1" readonly="1" height="200" width="600"/>
12+
<group col="2" colspan="8" attrs="{'invisible': [('state', '!=', 'init')]}">
13+
<button string="Cancel·lar" special="cancel" icon="gtk-close" colspan="1"/>
14+
<button string="Reexportar fitxers" name="reexport_files" type="object" icon="gtk-go-forward" colspan="1" />
15+
</group>
16+
<group col="2" colspan="8" attrs="{'invisible': [('state', '=', 'init')]}">
17+
<button string="Tancar" special="cancel" icon="gtk-close" colspan="1"/>
18+
</group>
19+
</form>
20+
</field>
21+
</record>
22+
<record id="action_wizard_giscedata_switching_log_reexport" model="ir.actions.act_window">
23+
<field name="name">Reexportar fitxer adjunts</field>
24+
<field name="type">ir.actions.act_window</field>
25+
<field name="res_model">wizard.giscedata.switching.log.reexport</field>
26+
<field name="view_type">form</field>
27+
<field name="view_mode">form</field>
28+
<field name="view_id" ref="view_wizard_giscedata_switching_log_reexport_form"/>
29+
<field name="target">new</field>
30+
</record>
31+
<record id="value_wizard_giscedata_switching_log_reexport" model="ir.values">
32+
<field name="object" eval="1"/>
33+
<field name="name">Reexportar fitxers adjunts</field>
34+
<field name="key2">client_action_multi</field>
35+
<field name="key">action</field>
36+
<field name="model">giscedata.switching.log</field>
37+
<field name="value" eval="'ir.actions.act_window,'+str(ref('action_wizard_giscedata_switching_log_reexport'))" />
38+
</record>
39+
</data>
40+
</openerp>

0 commit comments

Comments
 (0)