您的位置:首页 > 运维架构

OpenERP-隐藏多对多域弹出列表视图的"新建"按钮(Hide the "Create" button from the popup list view of a many2many field)

2014-08-05 23:33 399 查看
隐藏多对多域的弹出列表视图中的“新建”按钮,如例:

Hiding the "Create" button from the popup list view of a many2many field. Example shown as below:

1. 在.py文件中定义many2many的field:

1. Define a many2many field in the python source file

'a_m2m_field': fields.many2many('test2', 'test1_test_rel', 'test1_id', 'test2_id', string='M2M Field'),


2. 修改view_form.js,在大约4939行的位置,添加"var ctx = ..."至代码结尾的内容:

2. Modify the file view_form.js, insert the code from "var ctx = ..." to the end of code at about line 4939:

var $cbutton = self.$buttonpane.find(".oe_selectcreatepopup-search-create");
$cbutton.click(function() {
self.new_object();
});
var ctx = self.context.__contexts[0];
if(typeof(ctx) == "string"){
var ctxStr = ctx.replace("'", "\"", 'g');
var context = JSON.parse(ctxStr);
if(context.my_no_create && context.my_no_create != 0){
$cbutton.remove();
}
}


3. 修改XML文件,添加context:

3. Modify the XML file to add the context:

<field name="a_m2m_field" context="{'my_no_create': 1}">
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐