想要在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”。此功能的目的是向该组以外的用户隐藏聊天按钮。如果我将该行添加到基本文件中,它运行良好,但问题是在这种情况下它不起作用。
这就是我重写基本 js 脚本的方式
我已将 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())
请帮助我。
谢谢
最佳答案
您需要使用模板 ID 作为 im_chat.assets_backend,而不是 custom_unique_id。请在您的xml文件中添加以下代码并升级模块,您将看到模块的效果。
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="im_chat.assets_backend" name="im_chat assets"
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>
关于javascript - 如何在 odoo 8 中重写 js 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34529236/