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 @@ ...@@ -3,6 +3,7 @@
from osv import osv, fields from osv import osv, fields
from tools.translate import _ from tools.translate import _
class AnybusprocessTest(osv.TransientModel): class AnybusprocessTest(osv.TransientModel):
_name = 'anybus.process.test' _name = 'anybus.process.test'
_description = 'Anybus process test' _description = 'Anybus process test'
...@@ -10,22 +11,29 @@ class AnybusprocessTest(osv.TransientModel): ...@@ -10,22 +11,29 @@ class AnybusprocessTest(osv.TransientModel):
def _get_model(self, cr, uid, context=None): def _get_model(self, cr, uid, context=None):
if not context: if not context:
return [] return []
if (context.get('active_ids'), context.get('active_model')) == (None, None):
return []
if len(context['active_ids']) != 1: 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_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: if process.model_id:
return [(process.model_id.model, process.model_id.name)] return [(process.model_id.model, process.model_id.name)]
else: else:
model_obj = self.pool.get('ir.model') model_obj = self.pool.get('ir.model')
model_ids = model_obj.search(cr, uid, [], context=context) 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] return [(r['model'], r['name']) for r in models]
_columns = { _columns = {
'process_id': fields.integer('process', required=True), 'process_id': fields.integer('process', required=True),
'model': fields.reference('Model and id', selection=_get_model, size=128, required=True), 'model': fields.reference(
'state': fields.selection([('draft', 'Draft'), ('tested', 'Tested')], 'State', readonly=True), '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), 'result': fields.text('Result', readonly=True),
} }
...@@ -37,8 +45,11 @@ class AnybusprocessTest(osv.TransientModel): ...@@ -37,8 +45,11 @@ class AnybusprocessTest(osv.TransientModel):
def action_test(self, cr, uid, ids, context=None): def action_test(self, cr, uid, ids, context=None):
obj = self.pool.get(context['active_model']) obj = self.pool.get(context['active_model'])
this = self.browse(cr, uid, ids[0], context=context) 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) result = obj.process_process(
self.write(cr, uid, ids, {'state': 'tested', 'result': str(result)}, context=context) 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 { return {
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
'res_model': 'anybus.process.test', 'res_model': 'anybus.process.test',
...@@ -50,5 +61,4 @@ class AnybusprocessTest(osv.TransientModel): ...@@ -50,5 +61,4 @@ class AnybusprocessTest(osv.TransientModel):
'context': context, 'context': context,
} }
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # 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