diff --git a/addons/portal/__init__.py b/addons/portal/__init__.py index b0a7eb4ad50..47a320e7234 100644 --- a/addons/portal/__init__.py +++ b/addons/portal/__init__.py @@ -20,4 +20,5 @@ ############################################################################## import portal -import wizard \ No newline at end of file +import wizard +import ir_ui_menu \ No newline at end of file diff --git a/addons/portal/ir_ui_menu.py b/addons/portal/ir_ui_menu.py new file mode 100644 index 00000000000..f9c5fbf3f35 --- /dev/null +++ b/addons/portal/ir_ui_menu.py @@ -0,0 +1,53 @@ +# -*- 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 + +class portal_menu(osv.osv): + """Inherited menu class to customized the login search for menus, + as web client 6.0 does not support the menu action properly yet""" + + _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 current user belongs to a portal, we have to + # rewrite any search on the top menus to be under the + # portal's root menu: + if not context.get('ir.ui.menu.full_list') and \ + args and len(args) == 1 and \ + len(args[0]) == 3 and \ + (args[0][0] == 'parent_id' \ + and args[0][1] == '=' \ + and args[0][2] == False): + Portals = self.pool.get('res.portal') + portal_id = Portals.search(cr, uid, [('group_id.users', 'in', uid)]) + if portal_id: + assert len(portal_id) == 1, "Users may only belong to one portal at a time!" + portal_data = Portals.read(cr, uid, portal_id[0], ['parent_menu_id']) + menu_id_pair = portal_data.get('parent_menu_id') # (ID, Name) + if menu_id_pair: + args = [('parent_id', '=', menu_id_pair[0])] + ids = super(portal_menu, self).search(cr, uid, args, offset=0, + limit=None, order=order, context=context, count=False) + return len(ids) if count else ids +portal_menu() \ No newline at end of file