Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
7062 Lượt xem

We are using multi company structure. Company A and Company B.

A menuitem called "Recurring Invoice Pipeline" i want to hide for Company A and want to show for company B.

How to achieve this?



Ảnh đại diện
Huỷ bỏ
Tác giả

I want to hide a menuitem not a field.

Hello,

Have you found a solution that worked well for this?

I am using menuitems as quick filtering of data in Inventory. But these menuitems will not apply to the other company. I'm not sure if there is an easy solution for Odoo Online. Most users have multi company access.

Thanks

Câu trả lời hay nhất

You can apply record rules in menu item records. 

Create a method in the res.users model that will check if the current user is allowed to access the menu. Below is an actual example. Just add a condition to check for the company.

    def get_restricted_menus(self):
restricted_menu = ['sale.menu_sale_quotations',
'stock.menu_stock_warehouse_mgmt',
'sale.menu_sale_invoicing',
'mail.menu_root_discuss',
'contacts.menu_contacts',
'sale.menu_sale_order',
'sale.res_partner_menu']
menu_ids = []
for menu in restricted_menu:
try:
menu_ids.append(self.env.ref(menu).id)
except:
continue
return menu_ids


Then create a record rule assign it to the group. The domain is something like 

[('id', 'not in', user.get_restricted_menus())]








Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
it is definitely worked

1)create js file
odoo.define('your_module.HideMenuSection', function (require) {
"use strict";

var core = require('web.core');
var _t = core._t;
const ajax = require('web.ajax');
var SwitchCompanyMenu = require('web.SwitchCompanyMenu');
var session = require('web.session');

SwitchCompanyMenu.include({
_onSwitchCompanyClick: function (ev) {
if (session.user_context.allowed_company_ids) {
let cmp_id = session.user_context.allowed_company_ids[0];
ajax.jsonRpc("/switch/user/company", 'call', {
'company_id': cmp_id,
})
}
this._super.apply(this, arguments);
},
});
});

2)call the controller
from odoo.addons.website.controllers.main import Website



class BackendControllerInherit(Website):
"""Website Inherit"""

@http.route('/switch/user/company', type='json', auth="user")
def switch_user_company_details(self, company_id, **kw):
"""Check selected user company"""
restricted_menu = 'your_module.your_menuitem_id'
menu_id = None
try:
menu_id = request.env.ref(restricted_menu).id
except:
pass
if menu_id:
menu = request.env['ir.ui.menu'].browse(menu_id)
if company_id:
if company_id == 1:
menu.sudo().update({'active': False})
else:
menu.sudo().update({'active': True}) 
3) add link reference

odoo>
template id="assets_backend" name="claim assets backend" inherit_id="web.assets_backend">
xpath expr="." position="inside">
script type="text/javascript" src="/your_module_name/static/src/js/your_js_file_name.js"/>
/xpath>
/template>
/odoo>
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

Try create a boolean Field under company to show Recurring Invoice Pipeline menu and set the attrs invisible based on company boolean field.

Regards

Ảnh đại diện
Huỷ bỏ
Tác giả

I believe attrs not supported on menu item.
Can you share sample code/example to achieve solution given by you.

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 21
4116
1
thg 6 25
4058
0
thg 5 21
2119
3
thg 2 24
2515
1
thg 5 22
3389