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}">



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值