Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
1125 Zobrazení

Hi All, 

Thanks in Advance.

Only users with group 'base.group_system' should be able to see this Administration Category category. Other users Administration Category should be hidden


def get_application_groups(self, domain):

        if not self.env.user.sudo().has_group('base.group_system'):

            custom_group_id = self.env.sudo().ref('base.group_system')

            custom_admin_id = self.env.sudo().ref('base.group_erp_manager')

            excluded_groups = [custom_group_id, custom_admin_id]

            return self.search(domain + [('id', 'not in', excluded_groups)])

        return super(ResGroup, self).get_application_groups(domain)

I tried like this. But its not working.

Avatar
Zrušit

Does this works.

I also have similar requirement.

Autor Nejlepší odpověď

Hi,


Thanks for the replies, 

def get_application_groups(self, domain):

        if not self.env.user.sudo().has_group('base.group_erp_manager'):

            custom_group_id = self.env.sudo().ref('base.group_system')

            custom_admin_id = self.env.sudo().ref('base.group_erp_manager')

            excluded_groups = [custom_group_id, custom_admin_id]

            return self.search(domain + [('id', 'not in', excluded_groups)])

        return super(ResGroup, self).get_application_groups(domain)

i updated the code to this .

Error: Missing field string information for the field 'sel_groups_2_4' from the 'res.users' model


Now i get this error.

Avatar
Zrušit
Nejlepší odpověď

The issue is with how you're excluding the groups. You need to ensure that the excluded_groups list is populated correctly and check for the right conditions.

Key Changes:

  • Removed sudo() as it's unnecessary when checking group membership for the current user.
  • Used .id to ensure you're using the group IDs correctly when excluding.

This should now work, hiding the "Administration Category" for users not in base.group_system.


Avatar
Zrušit
Nejlepší odpověď

I'm not sure if there is something special here that you need to resort to python code to hide things in views. In normal scenario, I do it in the view's xml and simply add something like groups='base.group_system' to that elemement.

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
zář 22
3849
0
bře 19
2626
1
bře 15
5797
1
lis 21
5599
1
zář 17
3475