تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
797 أدوات العرض

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
يونيو 25
562
1
يونيو 25
709
1
يوليو 25
422
1
يونيو 25
558
1
يوليو 25
598