隐藏多对多域的弹出列表视图中的“新建”按钮,如例:
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}">
时间: 2024-10-10 09:17:48