콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
11282 화면

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?

아바타
취소
베스트 답변

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

아바타
취소
작성자

Thanks a lot! It worked exactly as I wanted.

Always welcome john_joe :) 👍

베스트 답변

this has change a bit in Odoo 16 and looks more like this:

def_get_view(self, view_id=None, view_type='form', **options):
arch, view = super()._get_view(view_id, view_type, **options)
if view_type in ('tree'):
nodes = arch.xpath("//tree")
for node in nodes:
# logic needed to switch create on or off               
if True:
node.set('create', '1')
return arch, view



아바타
취소
관련 게시물 답글 화면 활동
2
8월 21
13519
5
8월 20
7471
1
12월 19
5368
0
9월 17
3512
0
8월 17
2862