【发布时间】:2016-04-04 09:51:51
【问题描述】:
想要在 odoo 8 中自定义 IM 聊天按钮。我想让它对除一组之外的其他人不可见,所以我将 js 文件继承到我的模块中。原始文件是 im_chat.js 文件。
if(openerp.web && openerp.web.UserMenu) {
openerp.web.UserMenu.include({
do_update: function(){
var self = this;
var Users = new openerp.web.Model('res.users');
Users.call('has_group', ['bms.group_custom_chats']).done(function(is_employee) {
if (is_employee) {
self.update_promise.then(function() {
var im = new openerp.im_chat.InstantMessaging(self);
openerp.im_chat.single = im;
im.appendTo(openerp.client.$el);
var button = new openerp.im_chat.ImTopButton(this);
button.on("clicked", im, im.switch_display);
// button.appendTo(window.$('.oe_systray'));
});
}
});
return this._super.apply(this, arguments);
},
});
}
我在这里插入了“bms.group”而不是“base.group_user”。此功能的目的是将聊天按钮隐藏给该组以外的用户。如果我将该行添加到基本文件中,它运行良好,但在这种情况下它不起作用。
this is how is how I override the base js script
我已将 im_chat.js 文件保存到我的 srcopenerp.py 文件中。
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="custom_unique_id" name="some name to template" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/bms/static/src/js/im_chat.js"></script>
</xpath>
</template>
</data>
这是用于检查组用户的python代码。
@tools.ormcache(skiparg=2)
def has_group(self, cr, uid, group_ext_id):
"""Checks whether user belongs to given group.
:param str group_ext_id: external ID (XML ID) of the group.
Must be provided in fully-qualified form (``module.ext_id``), as there
is no implicit module to use..
:return: True if the current user is a member of the group with the
given external ID (XML ID), else False.
"""
assert group_ext_id and '.' in group_ext_id, "External ID must be fully qualified"
module, ext_id = group_ext_id.split('.')
cr.execute("""SELECT 1 FROM res_groups_users_rel WHERE uid=%s AND gid IN
(SELECT res_id FROM ir_model_data WHERE module=%s AND name=%s)""",
(uid, module, ext_id))
return bool(cr.fetchone())
请帮帮我。
谢谢
【问题讨论】:
标签: javascript python xml postgresql openerp