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

I have 3 user groups:

  • member
  • branch_manager (inherits member)
  • central_admin (inherits branch_manager)

Based on the user groups they need to see (or not) specific records / views / fields

How can I add some menus which will be visible only for member but not for branch_manager or central_admin, or others for branch_managers but hidden for central_admin ?

Some reasons:

  • members can see only a limited set of fields in a list (with no form)
  • branch managers should see a more detailed list with a form but only for members of the branches for which they manage (they can use the limited list above to see the others but not with a form)
  • central admin should see directly the full list and form for all members (not filtered) so the previous two are useless for them

Limiting menu access to specific user groups works fine, but because the groups are inheriting the lower ones central admin sees all of them

It would have been nice to be able to set negation of a group using ! like possible for fields, but apparently it's not supported for menu items

PS: as a side note I've also discovered that specifying groups_id on ir.ui.view and ir.actions.act_window doesn't actually protect them not to be opened by users which are not member of those groups, they can still access the actions and render the views if they access it by manipulating URL action-ID (I've raised a question on GitHub for this)

Avatar
Zrušit
Nejlepší odpověď

Hi,
If its possible to use custom modules, then try this app:  https://apps.odoo.com/apps/modules/17.0/kg_hide_menu

Thanks

Avatar
Zrušit
Nejlepší odpověď

try to use _get_view function

like this:


@api.model    
def _get_view(self, view_id=None, view_type='form', toolbar=False, submenu=False, **kwargs):        

result = super(ResPartner, self)._get_view(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu, **kwargs)

        doc = result[0]

        current_user_groups = self.env.user.groups_id.mapped('id')

        wanted_user_group = self.env.ref('model.wanted_user_group ').id

        if view_type == 'form' and wanted_user_group not in current_user_groups:            

​for field in doc.xpath("//field[@name='your_field']"):                

​field.set('readonly', '1')

        return result

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
3
pro 21
7268
0
pro 18
2591
7
říj 18
22405
2
lis 17
6623
0
dub 17
2640