简体   繁体   English

尝试在 Odoo 12 中调用向导时出现值错误

[英]Value error when trying to call a Wizard in Odoo 12

i am using odoo 12, and when trying to call a wizard in an action button it does not works我正在使用 odoo 12,当尝试在操作按钮中调用向导时它不起作用

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 model : model object 通过model_id链接到操作
  • record/records : record/recordset on which the action is triggered, can be void. record/records :触发操作的记录/记录集,可以是无效的。 env Odoo Environment env Odoo 环境
  • datetime, dateutil, time, timezone : corresponding Python modules datetime, dateutil, time, timezone : 对应的 Python 模块
  • log: log(message, level='info') : logging function to record debug information in ir.logging table log: log(message, level='info') : logging function 在 ir.logging 表中记录调试信息
  • Warning : constructor for the Warning exception WarningWarning异常的构造函数

Try to replace pdi_riesgo_wizard_evaluacion with records in the server action code:尝试将pdi_riesgo_wizard_evaluacion替换为服务器操作代码中的records

<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.您可以在mrp模块中找到一个示例,它使用记录调用button_plan方法。

What i needed to change was pdi_riesgo_enviar_a_evaluar我需要改变的是 pdi_riesgo_enviar_a_evaluar

for为了

    <!--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>

Also, i did not change the method i was calling, it stayed with self, ids另外,我没有改变我正在调用的方法,它与 self, ids 保持一致

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM