1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 # Copyright (C) 2010-2012 OpenERP s.a. (<http://openerp.com>).
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 from operator import itemgetter
24 from textwrap import dedent
25 from osv import fields, osv
28 class board_board(osv.osv):
30 _description = "Board"
35 def list(self, cr, uid, context=None):
36 Actions = self.pool.get('ir.actions.act_window')
37 Menus = self.pool.get('ir.ui.menu')
38 IrValues = self.pool.get('ir.values')
40 act_ids = Actions.search(cr, uid, [('res_model', '=', self._name)], context=context)
41 refs = ['%s,%s' % (Actions._name, act_id) for act_id in act_ids]
43 # cannot search "action" field on menu (non stored function field without search_fnct)
44 irv_ids = IrValues.search(cr, uid, [
45 ('model', '=', 'ir.ui.menu'),
46 ('key', '=', 'action'),
47 ('key2', '=', 'tree_but_open'),
48 ('value', 'in', refs),
50 menu_ids = map(itemgetter('res_id'), IrValues.read(cr, uid, irv_ids, ['res_id'], context=context))
51 menu_names = Menus.name_get(cr, uid, menu_ids, context=context)
52 return [dict(id=m[0], name=m[1]) for m in menu_names]
54 def _clear_list_cache(self):
55 self.list.clear_cache(self)
57 def create(self, cr, user, vals, context=None):
60 def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
62 Overrides orm field_view_get.
63 @return: Dictionary of Fields, arch and toolbar.
67 res = super(board_board, self).fields_view_get(cr, user, view_id, view_type,
68 context, toolbar=toolbar, submenu=submenu)
70 CustView = self.pool.get('ir.ui.view.custom')
71 vids = CustView.search(cr, user, [('user_id', '=', user), ('ref_id', '=', view_id)], context=context)
74 arch = CustView.browse(cr, user, view_id, context=context)
75 res['custom_view_id'] = view_id
76 res['arch'] = arch.arch
77 res['arch'] = self._arch_preprocessing(cr, user, res['arch'], context=context)
78 res['toolbar'] = {'print': [], 'action': [], 'relate': []}
81 def _arch_preprocessing(self, cr, user, arch, context=None):
82 from lxml import etree
83 def remove_unauthorized_children(node):
84 for child in node.iterchildren():
85 if child.tag == 'action' and child.get('invisible'):
88 child = remove_unauthorized_children(child)
92 if isinstance(s, unicode):
93 return s.encode('utf8')
96 archnode = etree.fromstring(encode(arch))
97 return etree.tostring(remove_unauthorized_children(archnode), pretty_print=True)
100 class board_create(osv.osv_memory):
102 def board_create(self, cr, uid, ids, context=None):
104 this = self.browse(cr, uid, ids[0], context=context)
106 view_arch = dedent("""<?xml version="1.0"?>
107 <form string="%s" version="7.0">
113 """.strip() % (this.name,))
115 view_id = self.pool.get('ir.ui.view').create(cr, uid, {
117 'model': 'board.board',
123 action_id = self.pool.get('ir.actions.act_window').create(cr, uid, {
127 'res_model': 'board.board',
130 'help': dedent('''<div class="oe_empty_custom_dashboard">
132 <b>This dashboard is empty.</b>
134 To add the first report into this dashboard, go to any
135 menu, switch to list or graph view, and click <i>'Add to
136 Dashboard'</i> in the extended search options.
138 You can filter and group data before inserting into the
139 dashboard using the search options.
145 menu_id = self.pool.get('ir.ui.menu').create(cr, uid, {
147 'parent_id': this.menu_parent_id.id,
148 'action': 'ir.actions.act_window,%s' % (action_id,)
151 self.pool.get('board.board')._clear_list_cache()
154 'type': 'ir.actions.client',
161 def _default_menu_parent_id(self, cr, uid, context=None):
162 _, menu_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'menu_reporting_dashboard')
165 _name = "board.create"
166 _description = "Board Creation"
169 'name': fields.char('Board Name', size=64, required=True),
170 'menu_parent_id': fields.many2one('ir.ui.menu', 'Parent Menu', required=True),
174 'menu_parent_id': _default_menu_parent_id,
177 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: