Setting views for an action window
A howto about setting views for an action window with OpenERP 6
Working with OpenERP, is very often designing a wizard (either a wizard.interface or a osv.osv_memory) that returns a new window, perhaps being the most common case of creating a series of objects and listing them in a new tab. In most cases, these window actions that are responsible for managing this work smoothly and their corresponding views are loaded correctly; however, when working on an implementation with a large number of modules installed, it is normal to inherit views, which in turn are inherited by another module, and these in turn by others, etc; also, if views' priorities are reassigned, things can get pretty tedious ...
To solve this problem (or rather as a good programming practice), we can do the following, both from a Python file and from an XML file:
- Launching specific views from a Python file:
view_list_id = self.pool.get('ir.ui.view').search(cr, 1, [('name', '=', '<tree view name to use>')])[0]
form_view_id = self.pool.get('ir.ui.view').search(cr, 1, [('name', '=', '<form view name to use>')])[0]
#Now, we define our window action...
return {
'name': _('Created ids from this wizard'),
'type': 'ir.actions.act_window',
'res_model': 'model.name',
'view_type': 'form',
'view_mode': 'tree,form',
'domain': "[('id', 'in', %s)]" % [<created_ids>],
'view_id': False,
'views': [(view_list_id, 'tree'),(form_view_id, 'form'), (False,'calendar'), (False, 'graph')]
}
Here the key is the attribute 'views' of the window action, which allows us to specify the ids of the views that we cast for each of the types available.
- Launching specific views from a XML file:
<record id="action_view_my_custom_model" model="ir.actions.act_window"> <field name="name">All Created Objects</field> <field name="type">ir.actions.act_window</field> <field name="res_model">my.model.name</field> <field name="view_type">form</field> </record> <record id="view_action_view_my_custom_model_tree" model="ir.actions.act_window.view"> <field eval="1" name="sequence"/> <field name="view_mode">tree</field> <field name="view_id" ref="id_tree_view_to_use"/> <field name="act_window_id" ref="action_view_my_custom_model"/> </record> <record id="action_project_invoices_form_view" model="ir.actions.act_window.view"> <field eval="2" name="sequence"/> <field name="view_mode">form</field> <field name="view_id" ref="id_form_view_to_use"/> <field name="act_window_id" ref="action_view_my_custom_model"/> </record>


Thank you very much!
If it were for the official doc... (No es mala, es canalla)
Greetings