如何将带有 ir.actions.server 的自定义子菜单从 Odoo9 迁移到 Odoo12?
How can I migrate a custom submenu with ir.actions.server from Odoo9 to Odoo12?
我有一个带有自定义子菜单的模块,用于在 Odoo9 中传输。
在xml中,我有这个代码:
<record id='action_menu_location_transfer_server' model='ir.actions.server'>
<field name="name">Custom Transfers</field>
<field name="model_id" ref="model_wizard_location_transfers_internal_transfer"/>
<field name="state">code</field>
<field name="code">action = self.custom_get_transfer_views(cr, uid, context=context)</field>
<field eval="True" name="condition"/>
</record>
<menuitem id="menu_refund_returns"
name="Custom Transfers"
action="action_menu_location_transfer_server"
parent="stock.menu_stock_warehouse_mgmt"
sequence="1"
groups="base.group_user"/>
但在 Odoo12 中,如果我尝试使用代码,它会显示此错误:
Odoo Server Error
Traceback (most recent call last):
File "/etc/odoo/server12/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 'self' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/etc/odoo/server12/odoo/http.py", line 656, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/etc/odoo/server12/odoo/http.py", line 314, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/etc/odoo/server12/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/etc/odoo/server12/odoo/http.py", line 698, in dispatch
result = self._call_function(**self.params)
File "/etc/odoo/server12/odoo/http.py", line 346, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/etc/odoo/server12/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/etc/odoo/server12/odoo/http.py", line 339, in checked_call
result = self.endpoint(*a, **kw)
File "/etc/odoo/server12/odoo/http.py", line 941, in __call__
return self.method(*args, **kw)
File "/etc/odoo/server12/odoo/http.py", line 519, in response_wrap
response = f(*args, **kw)
File "/etc/odoo/server12/addons/web/controllers/main.py", line 1269, in run
result = request.env['ir.actions.server'].browse([action_id]).run()
File "/etc/odoo/server12/odoo/addons/base/models/ir_actions.py", line 553, in run
res = func(action, eval_context=eval_context)
File "/etc/odoo/server12/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 "/etc/odoo/server12/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 "/etc/odoo/server12/odoo/tools/pycompat.py", line 86, in reraise
raise value.with_traceback(tb)
File "/etc/odoo/server12/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 'self' is not defined" while evaluating
'action = self.custom_get_transfer_views(cr, uid, context=context)'
Odoo 12 的代码有什么问题?
我已经尝试过使用 self、record、object,但没有任何变化。
你可以试试这个
<record id='action_menu_location_transfer_server' model='ir.actions.server'>
<field name="name">Custom Transfers</field>
<field name="model_id" ref="model_wizard_location_transfers_internal_transfer"/>
<field name="state">code</field>
<field name="code">model.custom_get_transfer_views()</field>
<field eval="True" name="condition"/>
</record>
v12 中不再使用 'cr, uid,',
可以添加'custom_get_transfer_views'方法的代码来修正
我有一个带有自定义子菜单的模块,用于在 Odoo9 中传输。
在xml中,我有这个代码:
<record id='action_menu_location_transfer_server' model='ir.actions.server'>
<field name="name">Custom Transfers</field>
<field name="model_id" ref="model_wizard_location_transfers_internal_transfer"/>
<field name="state">code</field>
<field name="code">action = self.custom_get_transfer_views(cr, uid, context=context)</field>
<field eval="True" name="condition"/>
</record>
<menuitem id="menu_refund_returns"
name="Custom Transfers"
action="action_menu_location_transfer_server"
parent="stock.menu_stock_warehouse_mgmt"
sequence="1"
groups="base.group_user"/>
但在 Odoo12 中,如果我尝试使用代码,它会显示此错误:
Odoo Server Error
Traceback (most recent call last):
File "/etc/odoo/server12/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 'self' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/etc/odoo/server12/odoo/http.py", line 656, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/etc/odoo/server12/odoo/http.py", line 314, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/etc/odoo/server12/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/etc/odoo/server12/odoo/http.py", line 698, in dispatch
result = self._call_function(**self.params)
File "/etc/odoo/server12/odoo/http.py", line 346, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/etc/odoo/server12/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/etc/odoo/server12/odoo/http.py", line 339, in checked_call
result = self.endpoint(*a, **kw)
File "/etc/odoo/server12/odoo/http.py", line 941, in __call__
return self.method(*args, **kw)
File "/etc/odoo/server12/odoo/http.py", line 519, in response_wrap
response = f(*args, **kw)
File "/etc/odoo/server12/addons/web/controllers/main.py", line 1269, in run
result = request.env['ir.actions.server'].browse([action_id]).run()
File "/etc/odoo/server12/odoo/addons/base/models/ir_actions.py", line 553, in run
res = func(action, eval_context=eval_context)
File "/etc/odoo/server12/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 "/etc/odoo/server12/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 "/etc/odoo/server12/odoo/tools/pycompat.py", line 86, in reraise
raise value.with_traceback(tb)
File "/etc/odoo/server12/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 'self' is not defined" while evaluating
'action = self.custom_get_transfer_views(cr, uid, context=context)'
Odoo 12 的代码有什么问题?
我已经尝试过使用 self、record、object,但没有任何变化。
你可以试试这个
<record id='action_menu_location_transfer_server' model='ir.actions.server'>
<field name="name">Custom Transfers</field>
<field name="model_id" ref="model_wizard_location_transfers_internal_transfer"/>
<field name="state">code</field>
<field name="code">model.custom_get_transfer_views()</field>
<field eval="True" name="condition"/>
</record>
v12 中不再使用 'cr, uid,',
可以添加'custom_get_transfer_views'方法的代码来修正