Why is my act_window with views = definitions and using the equivalent of act_window.view?

Let's say I have this:

<record id="mrp_bom_form_action_master_products" model="ir.actions.act_window">
  <field name="name">Master Bill of Materials</field>
  <field name="res_model">mrp.bom</field>
  <field name="view_type">form</field>
  <field name="view_mode">tree,form</field>
  <field name="view_id" eval="False"/>
  <field name="views" eval="[(False, 'tree'), (ref('mrp_bom_form_view_master'), 'form')]"/>
  <field name="search_view_id" ref="mrp.view_mrp_bom_filter"/>
</record>

      

According to the docs:

view

list of pairs (view_id, view_type). The second element of each pair is the view category (tree, form, graph, ...) and the first is an optional database identifier (or False). If no identifier is provided, the client should get a default view of the specified type for the requested model (this is done automatically using_view_get () fields). The first type of list is the default view type and will be opened by default when the action is taken. Each view type must appear at most once in the list

But that won't work. I did this instead:

<record model="ir.actions.act_window.view"
        id="mrp_bom_form_view_master_form">
  <field name="sequence" eval="1"/>
  <field name="view_mode">tree</field>
  <field name="act_window_id" ref="mrp_bom_form_action_master_products"/>
</record>

<record model="ir.actions.act_window.view"
        id="mrp_bom_form_view_master_tree">
  <field name="sequence" eval="2"/>
  <field name="view_mode">form</field>
  <field name="view_id" ref="mrp_bom_form_view_master"/>
  <field name="act_window_id" ref="mrp_bom_form_action_master_products"/>
</record>

      

Which works, but I don't understand why the first case doesn't.

+3


source to share


1 answer


The field views

in the model ir.actions.act_window

is an unsaved computed field with no inverse function. In other words, it is read-only and not even stored in the database. Therefore, when you create a new activity with this field, it is not saved and is simply ignored.

The documentation is a bit confusing (I also had a hard time figuring out what it was), but not technically wrong. This field is really a list of pairs (view_id, view_type)

, you simply cannot change it directly when working with actions stored in the database. It is generated automatically based on the view_id

and fields view_ids

.



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

:

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',
}

      

+4


source







All Articles