콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

Since Odoo 9 or 11, we use the feature "visible groups" for our website menus. Now in Odoo 16 the field is removed.


How to we restrict a menu item visibility to a certain user group in Odoo 16? Note, it's also about mege menu entries, page visibility *does not help*.

아바타
취소

Did you figure this out?

작성자

@Matthew Harrison Yes, we did, see my answer below.

작성자 베스트 답변

We developed a solution as part of https://apps.odoo.com/apps/modules/16.0/website_user_types/

The module makes the website menu tree visible outside debug mode. In the menus' form you can restrict a menu to specific website user groups, e.g. B2C and B2B. The important part is to consider the menu caching, too! In Odoo 16 the menu is cached and group visibility is not going to be recalculated without extending the t-cache. This can look like this:

< template
id="layout"
inherit_id="website.layout">
< xpath expr="//header/t[@t-cache]" position="attributes">
< attribute name="t-cache" add="website.get_website_user_group_cache_key()"/>
< /xpath>
< /template>

Depending on your use case you might add more groups. For us, the user groups fulfill the requirements.

아바타
취소

Hi Michael
What is the minimum things we need to change to show a menu based on group in website ?
I saw your module but it seems a lot of things to configure.
Can you provide a step by step guide to where to change ?
Thanks in Advance

작성자

@Gouranga Kala

You need to add the groups field, add the security filter for portal and public users (see website_user_types/security/website_security.xml or implement another solution), and extend the cache key in the header according to the group combinations.

베스트 답변

You can achieve it by inheriting the _compute_visible method of website.menu model.

Consider the below given example:-

class WebsiteMenu(models.Model):
_inherit = 'website.menu'


def _compute_visible(self):
"""Compute menu invisible"""
super()._compute_visible()
for menu in self:
if not menu.is_visible:
return
if menu.name == 'Shop' and not self.env.user.user_has_groups(
'base.group_user'):
menu.is_visible = False

Regards

아바타
취소
작성자

Thanks four your post. Please note, that this solution will not work seamlessly in Odoo 16 because the menu is cached. Thus, every odoo worker might cache a different version of the menu and the menu shown to the user will be depending on the worker who answers the request, but not his user group. To extend t-cache, see my answer above.

관련 게시물 답글 화면 활동
1
5월 25
1142
1
4월 24
1662
0
7월 24
256
1
8월 23
1987
0
5월 23
1520