尝试在 Odoo 12 中调用向导时出现值错误
Value error when trying to call a Wizard in Odoo 12
我正在使用 odoo 12,当尝试在操作按钮中调用向导时它不起作用
奇怪的是,如果我将向导用作按钮(仅用于测试),它会起作用。
这是我的代码
这是操作下拉按钮
<!--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>
这是我尝试调用的方法
@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
})
这是我遇到的错误
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()'
evaluation context 或周围的服务器操作中有许多键可用:
model
:通过 model_id
链接到动作的模型对象
record/records
:触发动作的record/recordset,可以为空。
env Odoo 环境
datetime, dateutil, time, timezone
:对应Python个模块
log: log(message, level='info')
: logging函数,用于记录ir.logging中的调试信息 table
Warning
:Warning
异常 的构造函数
尝试将服务器操作代码中的 pdi_riesgo_wizard_evaluacion
替换为 records
:
<field name="code">records.enviar_a_evaluar()</field>
并将方法的签名更改为:
enviar_a_evaluar(self):
示例:
@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
})
您可以在 mrp module, It calls the button_plan 方法中找到使用记录的示例。
我需要改变的是pdi_riesgo_enviar_a_evaluar
为
<!--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_wizard_evaluacion"/>
<field name="state">code</field>
<field name="code">
model.enviar_a_evaluar(model.env.context.get('active_ids'))
</field>
<field name="binding_model_id" ref="model_pdi_riesgo"/>
</record>
此外,我没有更改调用的方法,它保留在 self,ids
我正在使用 odoo 12,当尝试在操作按钮中调用向导时它不起作用
奇怪的是,如果我将向导用作按钮(仅用于测试),它会起作用。
这是我的代码
这是操作下拉按钮
<!--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>
这是我尝试调用的方法
@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
})
这是我遇到的错误
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()'
evaluation context 或周围的服务器操作中有许多键可用:
model
:通过model_id
链接到动作的模型对象
record/records
:触发动作的record/recordset,可以为空。 env Odoo 环境datetime, dateutil, time, timezone
:对应Python个模块log: log(message, level='info')
: logging函数,用于记录ir.logging中的调试信息 tableWarning
:Warning
异常 的构造函数
尝试将服务器操作代码中的 pdi_riesgo_wizard_evaluacion
替换为 records
:
<field name="code">records.enviar_a_evaluar()</field>
并将方法的签名更改为:
enviar_a_evaluar(self):
示例:
@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
})
您可以在 mrp module, It calls the button_plan 方法中找到使用记录的示例。
我需要改变的是pdi_riesgo_enviar_a_evaluar
为
<!--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_wizard_evaluacion"/>
<field name="state">code</field>
<field name="code">
model.enviar_a_evaluar(model.env.context.get('active_ids'))
</field>
<field name="binding_model_id" ref="model_pdi_riesgo"/>
</record>
此外,我没有更改调用的方法,它保留在 self,ids