Python 如何将Odoo中的菜单链接到计算URL
我需要将Odoo中的一个菜单项链接到一个外部链接,但是这个外部链接是存储在model中的字符串,对于每个用户来说都是不同的。我不知道如何在字段名Python 如何将Odoo中的菜单链接到计算URL,python,xml,openerp,Python,Xml,Openerp,我需要将Odoo中的一个菜单项链接到一个外部链接,但是这个外部链接是存储在model中的字符串,对于每个用户来说都是不同的。我不知道如何在字段名url的eval属性中对其进行编码。或者这是可能的 <openerp> <data> <record id="open_retainer" model="ir.actions.act_url"> <field name="name">Pay Retainer&l
url
的eval
属性中对其进行编码。或者这是可能的
<openerp>
<data>
<record id="open_retainer" model="ir.actions.act_url">
<field name="name">Pay Retainer</field>
<field name="type">ir.actions.act_url</field>
<field name="target">new</field>
<field name="url" eval="'some_url' if True else ''"/>
</record>
<menuitem
name="Pay Retainer"
id="menu_pay_retainer"
groups="base.group_portal"
action="open_retainer"
parent="portal.portal_orders"/>
</data>
</openerp>
薪酬聘请
ir.actions.act\u url
新的
您可以尝试单击用户屏幕中的按钮并重定向到特定的url,而不是使用as菜单
您可以尝试以下操作:
return { 'type': 'ir.actions.act_url', 'url': your_url, 'nodestroy': True, 'target': 'new' }
其中,“您的url”是为每个用户存储的url字符串。是的,这是可能的。下面是一个关于
ir\u actions\u act\u url
假设外部链接存储在res.users
model中。要根据用户重定向它,您需要继承ir.actions.act\u url
model。并修改读取方法。像
class ir_actions_act_url(osv.osv):
_inherit = 'ir.actions.act_url'
def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
if not context: context = {}
results = super(ir_actions_act_url, self).read(cr, uid, ids, fields=fields, context=context, load=load)
if len(ids) == 1:
user_obj = self.pool.get('res.users')
user_rec = user_obj.browse(cr, uid, uid, context=context)
if user_rec.external_link:
results[0].update({'url':user_rec.external_link})
return results
您可以根据需要修改逻辑
希望这有帮助。示例:
使用配置参数从菜单打开URL
网址
http://google.com.pe
操作\u打开\u url
ir.actions.server
url=env['ir.config_参数'].sudo().get_参数('url_网站')
action={“type”:“ir.actions.act\u url”,
“url”:url,
“目标”:“新建”}
我已经试过了,是的,这对我很有效。但我特别需要的是,用户不必打开按钮链接到方法的对话框。我希望该用户在单击菜单时,会自动打开外部url。谢谢@AtulArvind。我知道你代码的逻辑,但我想我只需要稍微修改一下,这样就不会适用于每一个act_url。一旦我以后尝试过这个,我会接受这个答案。