This question has been flagged
4 Replies
12312 Views

How to hide some groups from user form

For eg: Hiding group named 'Addresses in Sales Orders' from user form

Avatar
Discard
Best Answer

Hi,

You can check with "_update_user_groups_view"  function in the res_users.py (base -> res -> res_users.py ).

To hide your group,

field_name = name_boolean_group(g.id)
group_no_one = view.env.ref('base.group_no_one')
your_grp = view.env.ref('module_name.group_name')
if g == group_no_one or g == your_grp:
# make the group_no_one invisible in the form view
xml2.append(E.field(name=field_name, invisible="1", **attrs))
else:
xml2.append(E.field(name=field_name, **attrs))

This is the relevant part of the original code.


UPDATE:

In latest versions, see:https://www.youtube.com/watch?v=zbeBTImPKUw



Thanks

Avatar
Discard

I tested it in the original code. and its work fine.

Author

when the function is calling.. i think during create, write and unlink of groups. Then how it will work for existing groups

The function will get called during the create, write and unlink of the model res.groups. IT will affect the all groups , not only newly creating group.

Hello @Niyas Raphy,

Can you please help me inherit this method and hide the group "Use products on vendor bills" from the account module?

Thank you in advance

I saw this too, hoped there would be other way than to duplicate 100lines function just to change 2 lines.

Best Answer

you can simply create an invisible security category as following

<record model="ir.module.category" id="category_id>
<field name="name">Hidden Category</field>
<field name="visible" eval="0" />
</record> All the security groups that belongs to this category wouldn't be visible to the users
Avatar
Discard

doesn't work for me with odoo 13. it creates a new category named `hidden category` and the groups still appear on the user form

Best Answer

Hii,

class ResGroups(models.Model):
_inherit = 'res.groups'


def get_application_groups(self, domain):
sale_receipt_id = self.env.ref('account.group_sale_receipts').id
return super(ResGroups, self).get_application_groups(domain + [('id', '!=', sale_receipt_id)])

Thanks


Avatar
Discard

I tried on v14 but it didn't work. Do you have a solution?

Best Answer

 If hiding the whole category works for you,


def_get_hidden_extra_categories(self):

return ['base.module_category_hidden','base.module_category_extra','base.module_category_usability']

You can override this function in res.groups and add your group category to this function so that it will only be visible to base.group_no_one

Avatar
Discard