跳至内容
菜单
此问题已终结

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

形象
丢弃
编写者 最佳答案

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");

    },

});

形象
丢弃
最佳答案

Hello Shrey,

find the similar question: Click here

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

Thanks

形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
1
6月 25
581
1
6月 25
734
1
7月 25
441
1
6月 25
564
1
7月 25
600