Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
782 มุมมอง

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มิ.ย. 25
552
1
มิ.ย. 25
696
1
ก.ค. 25
414
1
มิ.ย. 25
550
Grouped Sums for computed fields แก้ไขแล้ว
1
ก.ค. 25
594