odooodoo-14odoo-15odoo-16

Is it possible to create alternate views to existing models in Odoo?


I have scoured the Odoo 16 documentation and searched Google for answers to this.

All I've found are examples of altering/modifying/overriding existing "tree, form, kanban" views. Nothing I find shows creating a brand new view for a model while retaining the existing views.

The odoo documentation tutorial follows this process:

  1. Create Model
  2. Create Action and bind it to Model <--- what!?
  3. Create View for the Model

The problem with the Odoo architecture demonstrated above is that actions go to models instead of views -- which makes views and models tightly-coupled. It looks impossible to make lots of different views for a single model and link actions to those views. Is it impossible to make new views and use them from different actions?

My specific use case is that I want to expose the Contact model view a custom Tree View and Form View in a custom module, but I do NOT want to show the full Contact information with all fields. I want to show a very small subset of fields.

If anyone can show documentation or clear code that does this, I would greatly appreciate it.


Solution

  • Use ir.actions.act_window.view as indicated in Window Actions section:

    If you plan to allow multiple views for your model, prefer using ir.actions.act_window.view

    Example:

    <record model="ir.actions.act_window.view" id="test_action_tree">
       <field name="sequence" eval="1"/>
       <field name="view_mode">tree</field>
       <field name="view_id" ref="view_test_tree"/>
       <field name="act_window_id" ref="test_action"/>
    </record>