1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2011 OpenERP S.A (<http://www.openerp.com>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
24 from osv import osv, fields
25 from tools.safe_eval import safe_eval
27 class portal_menu(osv.osv):
29 Fix menu class to customize the login search for menus,
30 as web client 6.0 does not support the menu action properly yet
33 _inherit = 'ir.ui.menu'
35 def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
39 # if the user belongs to a portal, we have to rewrite any search on the
40 # top menus to be under the portal's parent menu
41 if not context.get('ir.ui.menu.full_list') and uid != 1 and \
42 args == [('parent_id', '=', False)]:
43 portal_obj = self.pool.get('res.portal')
44 portal_ids = portal_obj.search(cr, uid, [('users', 'in', uid)])
46 if len(portal_ids) > 1:
47 log = logging.getLogger('ir.ui.menu')
48 log.warning('User %s belongs to several portals', str(uid))
49 p = portal_obj.browse(cr, uid, portal_ids[0])
50 # if the portal overrides the menu, use its domain
52 args = safe_eval(p.menu_action_id.domain)
54 return super(portal_menu, self).search(cr, uid, args, offset=offset,
55 limit=limit, order=order, context=context, count=count)