CIRUGÍA DEL SOFTWARE

Cabezera
You are here: Home Blog 2011 April 18 Setting views for an action window

Setting views for an action window

by alberto — last modified Apr 18, 2011 04:10 PM
Filed Under:

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:
    Let's imagine that the action of our wizard creates a series of objects and we want to show the freshly created ids. To do this and after having developed the logic of our function, we can return a dictionary containing an action window as follows:

 

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:
    In this case we use the model 'ir.actions.act_window_view' to ​​specify what views we want to launch of the total available (actually list, form, calendar or chart):

 

<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!

Posted by Anonymous User at May 16, 2012 07:29 PM
You made my day!
If it were for the official doc... (No es mala, es canalla)
Greetings

 
Logotipo pexego