1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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 ##############################################################################
22 from osv import fields, osv
24 class wiki_create_menu(osv.osv_memory):
26 _name = "wiki.create.menu"
27 _description = "Wizard Create Menu"
30 'menu_name': fields.char('Menu Name', size=256, select=True, required=True),
31 'menu_parent_id': fields.many2one('ir.ui.menu', 'Parent Menu', required=True),
34 def wiki_menu_create(self, cr, uid, ids, context):
36 """ Create Menu On the base of Group id and Action id
37 @param cr: the current row, from the database cursor,
38 @param uid: the current user’s ID for security checks,
39 @param ids: List of create menu’s IDs
42 obj_wiki_group = self.pool.get('wiki.groups')
43 obj_view = self.pool.get('ir.ui.view')
44 obj_menu = self.pool.get('ir.ui.menu')
45 obj_action = self.pool.get('ir.actions.act_window')
46 group_id = context.get('active_id', False)
50 datas = self.browse(cr, uid, ids, context=context)
59 'view_mode': 'form,tree',
60 'res_model': 'wiki.wiki',
62 'type': 'ir.actions.act_window',
65 group = obj_wiki_group.browse(cr, uid, group_id, context=context)
66 value['domain'] = "[('group_id','=',%d)]" % (group.id)
67 if group.method == 'page':
68 value['res_id'] = group.home.id
69 elif group.method == 'list':
70 value['view_type'] = 'form'
71 value['view_mode'] = 'tree,form'
72 elif group.method == 'tree':
73 view_id = obj_view.search(cr, uid, [('name', '=', 'wiki.wiki.tree.childs')])
74 value['view_id'] = view_id
75 value['domain'] = [('group_id', '=', group.id), ('parent_id', '=', False)]
76 value['view_type'] = 'tree'
78 action_id = obj_action.create(cr, uid, value)
80 menu_id = obj_menu.create(cr, uid, {
81 'name': data.menu_name,
82 'parent_id':data.menu_parent_id.id,
83 'icon': 'STOCK_DIALOG_QUESTION',
84 'action': 'ir.actions.act_window,'+ str(action_id),
86 obj_wiki_group.write(cr, uid, [group_id], {'menu_id':menu_id})
92 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: