This question has been flagged
2 Replies
8855 Views

I specified a tree view and action view to open the tree view for a model. It works as first with the following XML:

```

<record id="my_feature_tree" model="ir.ui.view">
  ...
</record>

<record id="action_my_feature_tree1" model="ir.actions.act_window">
  <field name="name">My Feature</field>
  <field name="res_model">my_module.my_model</field>
  <field name="view_type">form</field>
  <field name="view_mode">tree,kanban,form,pivot,graph</field>
  <field eval="False" name="view_id"/>
  <field name="domain">
    [('agent_id','!=',False)]
  </field>
  <!-- <field name="search_view_id" ref="view_account_invoice_filter"/> -->
</record>

<record id="action_my_feature_tree1_view1" model="ir.actions.act_window.view">
  <field eval="1" name="sequence"/>
  <field name="view_mode">tree</field>
  <field name="view_id" ref="my_feature_tree"/>
  <field name="act_window_id" ref="action_my_feature_tree1"/>
</record>

```

But when I remove the view_mode "form" and set view_type to "tree", the view is broken:

* tree view is missing entirely (only kanban, pivot and graph are available

Is this a bug? This tree view is just a database view and record creations is undesirable. I already added create="false" to the tree element to get rid of the "Create" and "Import" buttons, but still it opens the form when clicking on a line.

It would also solve my problem if I could specify another form view AND model to represent in the form view. But the tree model and the default form view cannot be used.

Thanks a lot!

Avatar
Discard
Best Answer

I found a workaround by specifying separate views for tree and form.

However, it does not really answer the question, because I did not find a way to disable the form view. It is still a bit confusing for the customer, it would be preferable not to open the form view at all because there are other clickable buttons in the rows. 

But I leave the workaround here for whoever needs it. You can create a custom action and assign custom action views to it like this:

  <record id="action_my_products" model="ir.actions.act_window">
    <field name="name">Products</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">product.product</field>
    <field name="view_mode">tree,form</field>
    <field name="view_id" ref="<tree_view_ref>"/>
  </record>

  <record id="action_my_products_tree" model="ir.actions.act_window.view">
    <field name="view_mode">tree</field>
    <field name="view_id" ref="<tree_view_ref>"/>
    <field name="act_window_id" ref="action_my_products"/>
  </record>

  <record id="action_my_product_form" model="ir.actions.act_window.view">
    <field name="view_mode">form</field>
    <field name="view_id" ref="<form_view_ref>"/>
    <field name="act_window_id" ref="action_my_products"/>
  </record>


Avatar
Discard
Best Answer

same problem

Avatar
Discard

In another, more recent project I used the above workaround with an informational dummy form view. Maybe it helps you, too.