This question has been flagged
2 Replies
8852 Views

Hello all,

In a window action, there is the field view_ids. This field is a one2many field. 

When I add this in the xml record, it doesn't work.

Should it work? 


        <record id="action_invoice_tree1_cf" model="ir.actions.act_window">
<field name="name">Sales invoices - CF action</field>
<field name="res_model">account.invoice</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field eval="False" name="view_id"/>
<field name="domain">[('type','=','out_invoice')]</field>
<field name="context">{'default_type':'out_invoice', 'type':'out_invoice', 'journal_type': 'sale'}</field>
<field name="search_view_id" ref="account.view_account_invoice_filter" />
<field name="limit" type="int">500</field>
             <field name="view_ids" eval="[(4, 0, [ref('account.invoice_form')])]" />
 
</record>

Avatar
Discard
Author

ABsolutely none example in all odoo 8 files for this.

Best Answer

The views field on the ir.actions.act_window model is a non-stored computed field, without an inverse function. In other words it's read-only and is not even stored in the database. That's why when you create a new action with this field, it is not saved and just gets ignored.

The documentation is a little confusing (I also had a hard time orginaly figuring this out), but not technically wrong. This field is indeed a list of (view_id, view_type) pairs, you just can't change it directly when dealing with actions stored in database. It is generated automatically, based on view_id and view_ids fields.

You can however use the field directly with actions that are not stored in the database, but returned from the python code instead. Here's an example taken from the account_payment module:

return {
    'name': _('Entry Lines'),
    'context': context,
    'view_type': 'form',
    'view_mode': 'form',
    'res_model': 'payment.order.create',
    'views': [(resource_id,'form')],
    'type': 'ir.actions.act_window',
    'target': 'new',
}
Avatar
Discard
Author

Ouf! I'm not crazy! Thanks a lot