Odoo/OpenERP:从树形视图中隐藏创建按钮 [英] Odoo/OpenERP: hiding create button from treeview
问题描述
我这里有个情况.我正在使用OpenERP7.我试图从产品的树形视图中隐藏创建"按钮.可以使用
I have a situation here. I am using OpenERP 7. I am trying to hide Create button from tree view of my products. this can be done using
<tree create="false" .....
但是情况就像.当用户直接从资产管理"模块打开树形视图时,我想保留它.但是当我单击Reporting for treeview时将其隐藏.
but situation is like. i want to keep it when user opens the tree view directly from "Asset Management" Module. But hide it when i click on Reporting for treeview.
我尝试通过报告按钮的功能使用这样的上下文:
I tried to use context like this from reporting button's function:
context['prod1']='false'
ctx = dict(context)
print ctx['prod1']
return {
'type': 'ir.actions.act_window',
'res_model': 'product.product',
'view_type': 'form',
'view_mode': 'tree,form',
'target': 'current',
'context':ctx,
'create':False,
'domain':[('id','in',domain)]
}
我以树状视图的形式完成了
and in treeview form I did:
<tree create="context.get('prod1',False)"
但是我得到了这个与json相关的错误:
but I get this json related error:
ERROR : SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
这些东西与我的按钮一起工作,但与我的树状视图一起工作.我也尝试添加'create':False
作为回报,但是无法做我想做的事情.我想念什么?
this stuff is working with my button but not with my tree view. I tried adding 'create':False
in return too, but unable to do what I want to. What am I missing?
推荐答案
我通过使用field_view_get成功解决了同样的问题:
I successfully solved the very same issue by using field_view_get:
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
res = models.Model.fields_view_get(self, cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
default_type = context.get('default_type', False)
can_create = default_type != 'out_customer_production'
update = not can_create and view_type in ['form', 'tree']
if update:
doc = etree.XML(res['arch'])
if not can_create:
for t in doc.xpath("//"+view_type):
t.attrib['create'] = 'false'
res['arch'] = etree.tostring(doc)
return res
(我没有创建属性就离开了树和表单视图)
(I left tree and form view without the create attribute)
这篇关于Odoo/OpenERP:从树形视图中隐藏创建按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!