[IMP] : Added context=None on methods used for _constraints and replaced context...
[odoo/odoo.git] / addons / board / wizard / board_menu_create.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from osv import fields, osv
23 from tools.translate import _
24
25 class board_menu_create(osv.osv_memory):
26     """
27     Create Menu
28     """
29     def view_init(self, cr, uid, fields, context=None):
30         """
31         This function checks for precondition before wizard executes
32         @param self: The object pointer
33         @param cr: the current row, from the database cursor,
34         @param uid: the current user’s ID for security checks,
35         @param fields: List of fields for default value
36         @param context: A standard dictionary for contextual values
37
38         check dashboard view on menu name field.
39         @return: False
40         """
41         data = context and context.get('active_id', False) or False
42         if data:
43             board = self.pool.get('board.board').browse(cr, uid, data, context=context)
44             if not board.line_ids:
45                 raise osv.except_osv(_('User Error!'),
46                                      _('Please Insert Dashboard View(s) !'))
47             return False
48
49
50     def board_menu_create(self, cr, uid, ids, context=None):
51         """
52         Create Menu.
53         @param cr: the current row, from the database cursor,
54         @param uid: the current user’s ID for security checks,
55         @param ids: List of Board Menu Create's IDs
56         @return: Dictionary {}.
57         """
58         if not context:
59             context = {}
60
61         context_id = context and context.get('active_id', False) or False
62         if context_id:
63             board = self.pool.get('board.board').browse(cr, uid, context_id, context=context)
64             action_id = self.pool.get('ir.actions.act_window').create(cr, uid, {
65                 'name': board.name,
66                 'view_type': 'form',
67                 'view_mode': 'form',
68                 'res_model': 'board.board',
69                 'view_id': board.view_id.id,
70                 })
71         obj_menu = self.pool.get('ir.ui.menu')
72         #start Loop
73         for data in self.read(cr, uid, ids):
74             obj_menu.create(cr, uid, {
75                 'name': data.get('menu_name'),
76                 'parent_id': data.get('menu_parent_id'),
77                 'icon': 'STOCK_SELECT_COLOR',
78                 'action': 'ir.actions.act_window,' + str(action_id)
79                 }, context=context)
80         #End Loop
81         return {}
82
83     _name = "board.menu.create"
84     _description = "Menu Create"
85
86     _columns = {
87              'menu_name': fields.char('Menu Name', size=64, required=True),
88              'menu_parent_id': fields.many2one('ir.ui.menu', 'Parent Menu', required=True),
89           }
90
91 board_menu_create()
92
93 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
94