diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index f9bd835156e..7b9d34b7623 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -265,6 +265,44 @@ def clean_action(action, session): action['flags'] = dict() return fix_view_modes(action) +def generate_views(action): + """ + While the server generates a sequence called "views" computing dependencies + between a bunch of stuff for views coming directly from the database + (the ``ir.actions.act_window model``), it's also possible for e.g. buttons + to return custom view dictionaries generated on the fly. + + In that case, there is no ``views`` key available on the action. + + Since the web client relies on ``action['views']``, generate it here from + ``view_mode`` and ``view_id``. + + Currently handles two different cases: + + * no view_id, multiple view_mode + * single view_id, single view_mode + + :param dict action: action descriptor dictionary to generate a views key for + """ + view_id = action.get('view_id', False) + if isinstance(view_id, (list, tuple)): + view_id = view_id[0] + + # providing at least one view mode is a requirement, not an option + view_modes = action['view_mode'].split(',') + + if len(view_modes) > 1: + if view_id: + raise ValueError('Non-db action dictionaries should provide ' + 'either multiple view modes or a single view ' + 'mode and an optional view id.\n\n Got view ' + 'modes %r and view id %r for action %r' % ( + view_modes, view_id, action)) + action['views'] = [(False, mode) for mode in view_modes] + return + action['views'] = [(view_id, view_modes[0])] + + def fix_view_modes(action): """ For historical reasons, OpenERP has weird dealings in relation to view_mode and the view_type attribute (on window actions): @@ -283,6 +321,9 @@ def fix_view_modes(action): :param dict action: an action descriptor :returns: nothing, the action is modified in place """ + if 'views' not in action: + generate_views(action) + if action.pop('view_type') != 'form': return diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index e4cc0172789..e9984c226da 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -1158,8 +1158,6 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({ "views":[[false,"form"]], "res_id": self.value[0], "type":"ir.actions.act_window", - "view_type":"form", - "view_mode":"form", "target":"new", "context": build_relation_context(self) }); diff --git a/addons/base_dashboard/static/src/js/dashboard.js b/addons/base_dashboard/static/src/js/dashboard.js index 70001374ae6..feb4e92d8a9 100644 --- a/addons/base_dashboard/static/src/js/dashboard.js +++ b/addons/base_dashboard/static/src/js/dashboard.js @@ -59,8 +59,6 @@ openerp.base.form.DashBoard = openerp.base.form.Widget.extend({ res_model : 'ir.actions.actions', views : [[false, 'list']], type : 'ir.actions.act_window', - view_type : 'list', - view_mode : 'list', limit : 80, auto_search : true, domain : [['type', '=', 'ir.actions.act_window']],