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-2013 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
26 from openerp import tools
27 from openerp.osv import fields, osv
29 class board_board(osv.osv):
31 _description = "Board"
36 def list(self, cr, uid, context=None):
37 Actions = self.pool.get('ir.actions.act_window')
38 Menus = self.pool.get('ir.ui.menu')
39 IrValues = self.pool.get('ir.values')
41 act_ids = Actions.search(cr, uid, [('res_model', '=', self._name)], context=context)
42 refs = ['%s,%s' % (Actions._name, act_id) for act_id in act_ids]
44 # cannot search "action" field on menu (non stored function field without search_fnct)
45 irv_ids = IrValues.search(cr, uid, [
46 ('model', '=', 'ir.ui.menu'),
47 ('key', '=', 'action'),
48 ('key2', '=', 'tree_but_open'),
49 ('value', 'in', refs),
51 menu_ids = map(itemgetter('res_id'), IrValues.read(cr, uid, irv_ids, ['res_id'], context=context))
52 menu_ids = Menus._filter_visible_menus(cr, uid, menu_ids, context=context)
53 menu_names = Menus.name_get(cr, uid, menu_ids, context=context)
54 return [dict(id=m[0], name=m[1]) for m in menu_names]
56 def _clear_list_cache(self):
57 self.list.clear_cache(self)
59 def create(self, cr, user, vals, context=None):
62 def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
64 Overrides orm field_view_get.
65 @return: Dictionary of Fields, arch and toolbar.
69 res = super(board_board, self).fields_view_get(cr, user, view_id, view_type,
70 context, toolbar=toolbar, submenu=submenu)
72 CustView = self.pool.get('ir.ui.view.custom')
73 vids = CustView.search(cr, user, [('user_id', '=', user), ('ref_id', '=', view_id)], context=context)
76 arch = CustView.browse(cr, user, view_id, context=context)
77 res['custom_view_id'] = view_id
78 res['arch'] = arch.arch
79 res['arch'] = self._arch_preprocessing(cr, user, res['arch'], context=context)
80 res['toolbar'] = {'print': [], 'action': [], 'relate': []}
83 def _arch_preprocessing(self, cr, user, arch, context=None):
84 from lxml import etree
85 def remove_unauthorized_children(node):
86 for child in node.iterchildren():
87 if child.tag == 'action' and child.get('invisible'):
90 child = remove_unauthorized_children(child)
94 if isinstance(s, unicode):
95 return s.encode('utf8')
98 archnode = etree.fromstring(encode(arch))
99 return etree.tostring(remove_unauthorized_children(archnode), pretty_print=True)
102 class board_create(osv.osv_memory):
104 def board_create(self, cr, uid, ids, context=None):
106 this = self.browse(cr, uid, ids[0], context=context)
108 view_arch = dedent("""<?xml version="1.0"?>
109 <form string="%s" version="7.0">
115 """.strip() % (this.name,))
117 view_id = self.pool.get('ir.ui.view').create(cr, uid, {
119 'model': 'board.board',
125 action_id = self.pool.get('ir.actions.act_window').create(cr, uid, {
129 'res_model': 'board.board',
132 'help': dedent('''<div class="oe_empty_custom_dashboard">
134 <b>This dashboard is empty.</b>
136 To add the first report into this dashboard, go to any
137 menu, switch to list or graph view, and click <i>'Add to
138 Dashboard'</i> in the extended search options.
140 You can filter and group data before inserting into the
141 dashboard using the search options.
147 menu_id = self.pool.get('ir.ui.menu').create(cr, uid, {
149 'parent_id': this.menu_parent_id.id,
150 'action': 'ir.actions.act_window,%s' % (action_id,)
153 self.pool.get('board.board')._clear_list_cache()
156 'type': 'ir.actions.client',
163 def _default_menu_parent_id(self, cr, uid, context=None):
164 _, menu_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'menu_reporting_dashboard')
167 _name = "board.create"
168 _description = "Board Creation"
171 'name': fields.char('Board Name', size=64, required=True),
172 'menu_parent_id': fields.many2one('ir.ui.menu', 'Parent Menu', required=True),
176 'menu_parent_id': _default_menu_parent_id,
179 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: