ir.ui.view: type field can be a functional field.

bzr revid: vmt@openerp.com-20120619101425-u73r47zdhsg7ecma
This commit is contained in:
Vo Minh Thu 2012-06-19 12:14:25 +02:00
parent 34b298f52d
commit ebf1383785
3 changed files with 21 additions and 8 deletions

View File

@ -47,11 +47,20 @@ view_custom()
class view(osv.osv):
_name = 'ir.ui.view'
def _type_field(self, cr, uid, ids, name, args, context=None):
records = self.browse(cr, uid, ids, context)
result = dict((r.id, etree.fromstring(r.arch.encode('utf8')).tag) for r in records)
return result
def _set_type_field(self, cr, uid, ids, name, value, args, context=None):
print "ignoring", value
_columns = {
'name': fields.char('View Name',size=64, required=True),
'model': fields.char('Object', size=64, required=True, select=True),
'priority': fields.integer('Sequence', required=True),
'type': fields.selection((
'type': fields.function(_type_field, fnct_inv=_set_type_field, type='selection', selection=[
('tree','Tree'),
('form','Form'),
('mdx','mdx'),
@ -60,7 +69,7 @@ class view(osv.osv):
('diagram','Diagram'),
('gantt', 'Gantt'),
('kanban', 'Kanban'),
('search','Search')), 'View Type', required=True, select=True),
('search','Search')], string='View Type', required=True, select=True, store=True),
'arch': fields.text('View Architecture', required=True),
'inherit_id': fields.many2one('ir.ui.view', 'Inherited View', ondelete='cascade', select=True),
'field_parent': fields.char('Child Field',size=64),
@ -133,7 +142,7 @@ class view(osv.osv):
super(view, self)._auto_init(cr, context)
cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = \'ir_ui_view_model_type_inherit_id\'')
if not cr.fetchone():
cr.execute('CREATE INDEX ir_ui_view_model_type_inherit_id ON ir_ui_view (model, type, inherit_id)')
cr.execute('CREATE INDEX ir_ui_view_model_type_inherit_id ON ir_ui_view (model, inherit_id)')
def get_inheriting_views_arch(self, cr, uid, view_id, model, context=None):
"""Retrieves the architecture of views that inherit from the given view, from the sets of

View File

@ -138,14 +138,17 @@ class module(osv.osv):
# We use try except, because views or menus may not exist.
try:
res_mod_dic = res[module_rec.id]
for v in view_obj.browse(cr, uid, imd_models.get('ir.ui.view', []), context=context):
view_ids = filter(None, imd_models.get('ir.ui.view', []))
for v in view_obj.browse(cr, uid, view_ids, context=context):
aa = v.inherit_id and '* INHERIT ' or ''
res_mod_dic['views_by_module'].append(aa + v.name + '('+v.type+')')
for rx in report_obj.browse(cr, uid, imd_models.get('ir.actions.report.xml', []), context=context):
report_ids = imd_models.get('ir.actions.report.xml', [])
for rx in report_obj.browse(cr, uid, filter(None, report_ids), context=context):
res_mod_dic['reports_by_module'].append(rx.name)
for um in menu_obj.browse(cr, uid, imd_models.get('ir.ui.menu', []), context=context):
menu_ids = imd_models.get('ir.ui.menu', [])
for um in menu_obj.browse(cr, uid, filter(None, menu_ids), context=context):
res_mod_dic['menus_by_module'].append(um.complete_name)
except KeyError, e:
_logger.warning(

View File

@ -605,8 +605,9 @@ form: module.record_id""" % (xml_id,)
"Verify that this is a window action or add a type argument." % (a_action,)
action_type,action_mode,action_name,view_id,target = rrres
if view_id:
cr.execute('SELECT type FROM ir_ui_view WHERE id=%s', (int(view_id),))
action_mode, = cr.fetchone()
cr.execute('SELECT arch FROM ir_ui_view WHERE id=%s', (int(view_id),))
arch, = cr.fetchone()
action_mode = etree.fromstring(arch.encode('utf8')).tag
cr.execute('SELECT view_mode FROM ir_act_window_view WHERE act_window_id=%s ORDER BY sequence LIMIT 1', (int(a_id),))
if cr.rowcount:
action_mode, = cr.fetchone()