Se rendre au contenu
Menu
Cette question a été signalée

I want to show the Documentation, Support, and My Odoo.com account menus only to admin users. 

I've used the following code, but it hasn't worked

/** @odoo-module **/


import { patch } from "@web/core/utils/patch";

import { registry } from "@web/core/registry";

import { _t } from "@web/core/l10n/translation";


const userMenuRegistry = registry.category("user_menuitems");


const ALLOWED_GROUPS = [

    "base.group_system",

    "sales_team.group_sale_manager",

];


function isUserAllowed(env) {

    const user = env.services.user;

    return user && ALLOWED_GROUPS.some(group => user.hasGroup(group));

}


patch(userMenuRegistry.get("documentation"), {

    show(env) {

        return isUserAllowed(env);

    },

});


patch(userMenuRegistry.get("support"), {

    show(env) {

        return isUserAllowed(env);

    },

});


patch(userMenuRegistry.get("odoo_account"), {

    show(env) {

        return isUserAllowed(env);

    },

});

Odoo v18 Community Edition

Avatar
Ignorer
Auteur Meilleure réponse

I've been able to use the following code to hide these menu items for all users. I'm unable to access the user group and conditionally hide it.

/** @odoo-module **/


import { registry } from "@web/core/registry";

import { UserMenu } from "@web/webclient/user_menu/user_menu";

import { patch } from "@web/core/utils/patch";


const originalUserMenuSetup = UserMenu.prototype.setup;


patch(UserMenu.prototype, {

    setup() {

        if (originalUserMenuSetup) {

            originalUserMenuSetup.apply(this, arguments); // 'this' is the current component instance

        }


        const userMenuRegistry = registry.category("user_menuitems");

        userMenuRegistry.add("credits", this._getStaticPageItem.bind(this));


        userMenuRegistry.remove("documentation");

        userMenuRegistry.remove("support");

        userMenuRegistry.remove("odoo_account");

    },

});

Avatar
Ignorer
Meilleure réponse

Hello Shrey,

find the similar question: Click here

or you can check this third party app as well : click here

Thanks

Avatar
Ignorer
Meilleure réponse

Hii,

Updated Working Code:

/** @odoo-module **/ import { patch } from "@web/core/utils/patch"; import { registry } from "@web/core/registry"; function isAdminUser(env) { return env.services.session.user_context?.is_admin_user; } const userMenuRegistry = registry.category("user_menuitems"); patch(userMenuRegistry.get("documentation"), { show(env) { return isAdminUser(env); }, }); patch(userMenuRegistry.get("support"), { show(env) { return isAdminUser(env); }, }); patch(userMenuRegistry.get("odoo_account"), { show(env) { return isAdminUser(env); }, });

Then on the Python side, expose is_admin_user in the session:

In your custom module:

models/res_users.py:

from odoo import models class ResUsers(models.Model): _inherit = "res.users" def _get_session_info(self): result = super()._get_session_info() result['user_context']['is_admin_user'] = self.has_group("base.group_system") return result

i hope it is use full

Avatar
Ignorer
Publications associées Réponses Vues Activité
1
juin 25
556
1
juin 25
699
1
juil. 25
416
1
juin 25
556
1
juil. 25
598