diff --git a/addons/portal/__init__.py b/addons/portal/__init__.py index 5aea1cf958f..4a16a77503c 100644 --- a/addons/portal/__init__.py +++ b/addons/portal/__init__.py @@ -21,4 +21,5 @@ import portal import wizard +import ir_ui_menu diff --git a/addons/portal/ir_ui_menu.py b/addons/portal/ir_ui_menu.py new file mode 100644 index 00000000000..210a305aef5 --- /dev/null +++ b/addons/portal/ir_ui_menu.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2011 OpenERP S.A (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from osv import osv, fields +from tools.safe_eval import safe_eval + +class portal_menu(osv.osv): + """ + Fix menu class to customize the login search for menus, + as web client 6.0 does not support the menu action properly yet + """ + _name = 'ir.ui.menu' + _inherit = 'ir.ui.menu' + + def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): + if context is None: + context = {} + + # if the user belongs to a portal, we have to rewrite any search on the + # top menus to be under the portal's parent menu + if not context.get('ir.ui.menu.full_list') and uid != 1 and \ + args == [('parent_id', '=', False)]: + portal_obj = self.pool.get('res.portal') + portal_ids = portal_obj.search(cr, uid, [('users', 'in', uid)]) + if portal_ids: + assert len(portal_ids) == 1 + p = portal_obj.browse(cr, uid, portal_ids[0]) + # if the portal overrides the menu, use its domain + if p.menu_action_id: + args = safe_eval(p.menu_action_id.domain) + + return super(portal_menu, self).search(cr, uid, args, offset=offset, + limit=limit, order=order, context=context, count=count) + +portal_menu() +