コンテンツへスキップ
メニュー
この質問にフラグが付けられました

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
619
1
6月 25
777
1
7月 25
499
1
6月 25
599
1
7月 25
646