首页 > 代码库 > OpenERP-隐藏多对多域弹出列表视图的"新建"按钮(Hide the "Create" button from the popup list view of a many2many field)
OpenERP-隐藏多对多域弹出列表视图的"新建"按钮(Hide the "Create" button from the popup list view of a many2many field)
隐藏多对多域的弹出列表视图中的“新建”按钮,如例:
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}">
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。