1 ##############################################################################
3 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 ##############################################################################
30 from osv import fields,osv
33 def _check_xml(self, cr, uid, ids):
35 cr.execute('select arch from ir_ui_view where id in ('+','.join(map(str,ids))+')')
36 for row in cr.fetchall():
37 doc = dom.minidom.parseString(row[0])
45 'name': fields.char('View Name',size=64, required=True),
46 'model': fields.char('Model', size=64, required=True),
47 'priority': fields.integer('Priority', required=True),
48 'type': fields.selection((
52 ('calendar', 'Calendar')), 'View Type', required=True),
53 'arch': fields.text('View Architecture', required=True),
54 'inherit_id': fields.many2one('ir.ui.view', 'Inherited View'),
55 'field_parent': fields.char('Childs Field',size=64)
58 'arch': lambda *a: '<?xml version="1.0"?>\n<tree title="Unknwown">\n\t<field name="name"/>\n</tree>',
59 'priority': lambda *a: 16
63 (_check_xml, 'Invalid XML for View Architecture!', ['arch'])
68 class view_sc(osv.osv):
69 _name = 'ir.ui.view_sc'
71 'name': fields.char('Shortcut Name', size=64, required=True),
72 'res_id': fields.integer('Resource Ref.', required=True),
73 'sequence': fields.integer('Sequence'),
74 'user_id': fields.many2one('res.users', 'User Ref.', required=True, ondelete='cascade'),
75 'resource': fields.char('Resource Name', size=64, required=True)
77 def create(self, cr, uid, vals, context=None):
78 id=self.pool.get('ir.values').search(cr,uid,[('res_id','=',vals['res_id'])])
80 return super(view_sc, self).create(cr, uid, vals, context=context)
82 raise osv.except_osv('Note !','You can not add root node as shortcut !')
84 def get_sc(self, cr, uid, user_id, model='ir.ui.menu', context={}):
85 ids = self.search(cr, uid, [('user_id','=',user_id),('resource','=',model)], context=context)
86 return self.read(cr, uid, ids, ['res_id','name'], context=context)
90 'resource': lambda *a: 'ir.ui.menu',