Ajuda

0

How to hide create button in tree view for all users except one group?

Avatar
dohn_joe

I know I can set create=False to hide it from everyone but I would like to be able to see it when I'm in certain group. How can I do it?

Avatar
Descartar
1 Resposta
9
Avatar
Yogendrasinh Chavda
Best Answer

Hello dohn_joe,

You can do by overriding fields_view_get method.

here I give you the example of fields_view_get:

For E.g:

    from lxml import etree

    def fields_view_get(self, cr, uid, view_id=None, view_type='tree',

        context=None, toolbar=False, submenu=False):

        if context is None:context = {}

        res = super(class_name, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type,

                    context=context, toolbar=toolbar, submenu=False)

        group_id = self.pool.get('res.users').has_group(cr, uid, 'modulename.group_xml_id')

        doc = etree.XML(res['arch'])

        if group_id:

            if view_type == 'tree':

                nodes = doc.xpath("//tree[@string='Test Tree']")

                for node in nodes:

                    node.set('create', '0')

                res['arch'] = etree.tostring(doc)

        return res

I hope this will helpful for you.

thanks

2 Comentários
Avatar
Descartar
Avatar
dohn_joe
-

Thanks a lot! It worked exactly as I wanted.

Avatar
Yogendrasinh Chavda
-

Always welcome john_joe :) 👍