This question has been flagged
1 Reply
6044 Views

Is there a way to hide the Import button in the tree view for specific groups / users?

Avatar
Discard
Best Answer

Place the following code inside the model file:-

@api.model
def fields_view_get(self, view_id=None, view_type='form',
toolbar=False, submenu=False):
result = super(<<<Module Name>>>>, self).fields_view_get(
view_id=view_id, view_type=view_type,
toolbar=toolbar, submenu=submenu)

# Disabling the import button for users who are not in import group
if view_type == 'tree':
doc = etree.XML(result['arch'])
if not self.env.user.has_group('<<<group_id>>>'):
         # When the user is not part of the import group
for node in doc.xpath("//tree"):
                # Set the import to false
                node.set('import', 'false')
result['arch'] = etree.tostring(doc)

    return result    ​

Based on the answer here - \https://www.odoo.com/forum/help-1/question/how-to-hide-create-button-in-tree-view-for-all-users-except-one-group-123564


Avatar
Discard