Odoo/OpenERP: hiding create button from treeview

强颜欢笑 提交于 2019-12-01 03:36:32

Are the views your accessing the same or are they different ?

If they are different, I believe the proper way to implement your requirement is to override the relevant view with the

create="false"

property you mentioned.

From the technical memento:

View Inheritance

Existing views should be modifying through inherited views, never directly. An inherited view references its parent view using the inherit_id field, and may add or modify existing elements in the view by referencing them through XPath expressions, and specifying the appropriate position.

Hope this helps.

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)

Don't know how to do it in python + xml either, i would stick with javascript extension, that gets data from context or from fields and disable and hide button depending on that data.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!