Commit a7b9b66a authored by jssuzanne's avatar jssuzanne
Browse files

Fix, check if active_ids and active_model existe before use it

parent b51f6558a4e4
......@@ -3,6 +3,7 @@
from osv import osv, fields
from tools.translate import _
class AnybusprocessTest(osv.TransientModel):
_name = 'anybus.process.test'
_description = 'Anybus process test'
......@@ -10,22 +11,29 @@ class AnybusprocessTest(osv.TransientModel):
def _get_model(self, cr, uid, context=None):
if not context:
return []
if (context.get('active_ids'), context.get('active_model')) == (None, None):
return []
if len(context['active_ids']) != 1:
raise osv.except_osv(_('Test process'), _('You must select one and only one process'))
raise osv.except_osv(_('Test process'),
_('You must select one and only one process'))
process_obj = self.pool.get(context['active_model'])
process = process_obj.browse(cr, uid, context['active_id'], context=context)
process = process_obj.browse(
cr, uid, context['active_id'], context=context)
if process.model_id:
return [(process.model_id.model, process.model_id.name)]
else:
model_obj = self.pool.get('ir.model')
model_ids = model_obj.search(cr, uid, [], context=context)
models = model_obj.read(cr, uid, model_ids, ['model', 'name'], context=context)
models = model_obj.read(
cr, uid, model_ids, ['model', 'name'], context=context)
return [(r['model'], r['name']) for r in models]
_columns = {
'process_id': fields.integer('process', required=True),
'model': fields.reference('Model and id', selection=_get_model, size=128, required=True),
'state': fields.selection([('draft', 'Draft'), ('tested', 'Tested')], 'State', readonly=True),
'model': fields.reference(
'Model and id', selection=_get_model, size=128, required=True),
'state': fields.selection(
[('draft', 'Draft'), ('tested', 'Tested')], 'State', readonly=True),
'result': fields.text('Result', readonly=True),
}
......@@ -37,8 +45,11 @@ class AnybusprocessTest(osv.TransientModel):
def action_test(self, cr, uid, ids, context=None):
obj = self.pool.get(context['active_model'])
this = self.browse(cr, uid, ids[0], context=context)
result = obj.process_process(cr, uid, this.process_id, this.model._name, [this.model.id], context=context)
self.write(cr, uid, ids, {'state': 'tested', 'result': str(result)}, context=context)
result = obj.process_process(
cr, uid, this.process_id, this.model._name, [this.model.id],
context=context)
self.write(cr, uid, ids, {'state': 'tested', 'result': str(result)},
context=context)
return {
'type': 'ir.actions.act_window',
'res_model': 'anybus.process.test',
......@@ -50,5 +61,4 @@ class AnybusprocessTest(osv.TransientModel):
'context': context,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment