Skip to Content
मेन्यू
This question has been flagged
4 Replies
1559 Views

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
Discard

Does this works.

I also have similar requirement.

Author Best Answer

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
Discard
Best Answer

Hi,

If you only want system users (base.group_system) to see the Administration category and its groups, you should filter by the category_id of the groups.

from odoo import models


class ResGroups(models.Model):

    _inherit = 'res.groups'

    def get_application_groups(self, domain):

        # If current user is NOT in system group

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

            # Get the Administration category record

            admin_category = self.env.ref('base.module_category_administration')

            # Exclude all groups in that category

            domain += [('category_id', '!=', admin_category.id)]

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


Hope it helps.

Avatar
Discard
Best Answer

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
Discard
Best Answer

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
Discard
Related Posts Replies Views Activity
2
सित॰ 22
4190
0
मार्च 19
2839
1
मार्च 15
6023
1
नव॰ 21
5999
1
सित॰ 17
3788