Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
864 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
3
dic 21
7273
0
dic 18
2592
7
ott 18
22408
2
nov 17
6625
0
apr 17
2641