تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
11280 أدوات العرض

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
أغسطس 21
13515
5
أغسطس 20
7467
1
ديسمبر 19
5368
0
سبتمبر 17
3509
0
أغسطس 17
2861