i am using odoo 12, and when trying to call a wizard in an action button it does not works
What is weird is if i use the wizard as a button (just for testing) it works.
Here is my code
This is the action dropdown button
<!--action dropdown-->
<record id="action_enviar_a_evaluacion" model="ir.actions.server">
<field name="name">Enviar a evaluacion</field>
<field name="model_id" ref="model_pdi_riesgo"/>
<field name="state">code</field>
<field name="code">
pdi_riesgo_wizard_evaluacion.enviar_a_evaluar()
</field>
<field name="binding_model_id" ref="model_pdi_riesgo"/>
</record>
And this is the method i am trying to call
@api.multi
def enviar_a_evaluar(self,ids):
r_fase_en_evaluacion=self.env['pdi.riesgo.fase'].search([('sequence','=',2)])
#self.riesgo.fase_evaluacion=r_fase_en_evaluacion.id
registros = self.browse(ids)
for riesgo in registros:
riesgo.fase_evaluacion=r_fase_en_evaluacion.id
record=self.env['pdi.riesgo.evaluacion'].sudo().create({
'riesgo':riesgo.id,
'fase':r_fase_en_evaluacion.id,
'comentario':'Se envia a evaluar',
'fecha_limite':self.fecha_limite
})
and this is the error i am getting
Error:
Odoo Server Error
Traceback (most recent call last):
File "D:\Odoo 12.0\server\odoo\tools\safe_eval.py", line 350, in safe_eval
return unsafe_eval(c, globals_dict, locals_dict)
File "", line 1, in <module>
NameError: name 'pdi_riesgo_wizard_evaluacion' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Odoo 12.0\server\odoo\http.py", line 656, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "D:\Odoo 12.0\server\odoo\http.py", line 314, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "D:\Odoo 12.0\server\odoo\tools\pycompat.py", line 87, in reraise
raise value
File "D:\Odoo 12.0\server\odoo\http.py", line 698, in dispatch
result = self._call_function(**self.params)
File "D:\Odoo 12.0\server\odoo\http.py", line 346, in _call_function
return checked_call(self.db, *args, **kwargs)
File "D:\Odoo 12.0\server\odoo\service\model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "D:\Odoo 12.0\server\odoo\http.py", line 339, in checked_call
result = self.endpoint(*a, **kw)
File "D:\Odoo 12.0\server\odoo\http.py", line 941, in __call__
return self.method(*args, **kw)
File "D:\Odoo 12.0\server\odoo\http.py", line 519, in response_wrap
response = f(*args, **kw)
File "d:\odoo 12.0\server\odoo\addons\web\controllers\main.py", line 1269, in run
result = request.env['ir.actions.server'].browse([action_id]).run()
File "d:\odoo 12.0\server\odoo\addons\base\models\ir_actions.py", line 553, in run
res = func(action, eval_context=eval_context)
File "d:\odoo 12.0\server\odoo\addons\base\models\ir_actions.py", line 444, in run_action_code_multi
safe_eval(action.sudo().code.strip(), eval_context, mode="exec", nocopy=True) # nocopy allows to return 'action'
File "D:\Odoo 12.0\server\odoo\tools\safe_eval.py", line 373, in safe_eval
pycompat.reraise(ValueError, ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr)), exc_info[2])
File "D:\Odoo 12.0\server\odoo\tools\pycompat.py", line 86, in reraise
raise value.with_traceback(tb)
File "D:\Odoo 12.0\server\odoo\tools\safe_eval.py", line 350, in safe_eval
return unsafe_eval(c, globals_dict, locals_dict)
File "", line 1, in <module>
ValueError: <class 'NameError'>: "name 'pdi_riesgo_wizard_evaluacion' is not defined" while evaluating
'pdi_riesgo_wizard_evaluacion.enviar_a_evaluar()'
A number of keys are available in the evaluation context of or surrounding server actions:
model
: model object linked to the action via model_id
record/records
: record/recordset on which the action is triggered, can be void.
env Odoo Environmentdatetime, dateutil, time, timezone
: corresponding Python moduleslog: log(message, level='info')
: logging function to record debug information in ir.logging tableWarning
: constructor for the Warning
exceptionTry to replace pdi_riesgo_wizard_evaluacion
with records
in the server action code:
<field name="code">records.enviar_a_evaluar()</field>
And change the signature of the method to:
enviar_a_evaluar(self):
Example:
@api.multi
def enviar_a_evaluar(self):
r_fase_en_evaluacion = self.env['pdi.riesgo.fase'].search([('sequence', '=', 2)])
for riesgo in self:
riesgo.fase_evaluacion = r_fase_en_evaluacion.id
self.env['pdi.riesgo.evaluacion'].sudo().create({
'riesgo': riesgo.id,
'fase': r_fase_en_evaluacion.id,
'comentario': 'Se envia a evaluar',
'fecha_limite': riesgo.fecha_limite
})
You can find an example in the mrp module, It calls the button_plan method using records.