我需要将Odoo中的菜单项链接到外部链接,但是此外部链接是存储在模型中的字符串,并且对于每个用户而言都是不同的。我不确定如何在字段名称eval
的url
属性中对此进行编码。还是可能?
<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>
您可以通过单击用户屏幕上的按钮来尝试重定向到特定的URL,而不是使用菜单。
您可以尝试以下操作:
return { 'type': 'ir.actions.act_url', 'url': your_url, 'nodestroy': True, 'target': 'new' }
其中'您的URL'是为每个用户存储的URL字符串。
是的,有可能。这是关于ir_actions_act_url
的简单想法假设外部链接存储在res.users
模型中。要根据用户重定向它,您需要继承ir.actions.act_url
模型。并修改读取方法。喜欢
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
<record id="url_website" model="ir.config_parameter">
<field name="key">url_website</field>
<field name="value">http://google.com.pe</field>
</record>
<record model="ir.actions.server" id="action_open_url">
<field name="name">action_open_url</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="code">
url = env['ir.config_parameter'].sudo().get_param('url_website')
action = {"type": "ir.actions.act_url",
"url": url,
"target": "new",}
</field>
</record>
<menuitem id="menu_open_url"
name="OPEN MY URL"
action="action_open_url"
/>