Search Here

Display multiple form and tree view for same model

In this tutorial you will learn how to display two or more form and tree view for same model. You can define different tree and form view for same model. To achieve this we will create a split action for our object/model.

Display Multiple Form and Tree View for Same Model

Problem Statement

First of all you may know the problem that what's the problem that we are facing here. For example we have a model "model.A" and we have also a tree and form view associated with that model (model.A). And we have one menu named "menuA", and this menu is visible to the only one group of users such as "Staff". 

When any user related to staff group will click on "menuA" than our above created form and tree view will be displayed to the cited user. And for that group of users we need that all the fields should be editable mode. That's working fine. 

Now the problem is what we have do when we have different group of users, and for that users we need to show some fields in readonly mode.

Read More: How to use attrs readonly and invisible in fields  

Solution

To do that we have different solutions but here we are going to resolve this issue by splitting action window. First we will create a new form and tree view which we want to show different group of users. 


Than we will create an action window using "ir.actions.act_window" model. If you want to read more about action window read this article Action Window in Odoo.


<record model="ir.actions.act_window" id="parent_action_window">
<field name="name">Parent Action Window</field>
<field name="res_model">model.A</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>

Now that we have created new form and tree view and action window. Now we are going to split action window using "ir.actions.act_window.view". The purpose of splitting the action window is to use our newly created form and tree view.

<record id="child_action_window_tree" model="ir.actions.act_window.view">
<field name="view_mode">tree</field>
<field name="view_id" ref="newly_created_tree_view_id_goes_here" />
<field name="act_window_id" ref="parent_action_window" />
</record>

<record id="child_action_window_form" model="ir.actions.act_window.view"> <field name="view_mode">form</field> <field name="view_id" ref="newly_created_form_view_id_goes_here" /> <field name="act_window_id" ref="parent_action_window" />
</record>

Code Description

In above code we have created two action window of type "ir.actions.act_window.view". In that action window we have mentioned the id of our newly created form and tree view and the id of parent action window.


Now we will call our newly created from and tree view by creating a new menu named "menuB".

<menuitem name="menuB" id="newly_created_menuB" action="parent_action_window" groups="your_group_goes_here"/>

Code Description

In above code we have created a new menu and associate new parent action window that we have created above. Now we have two menus (menuA and menuB). When we click on menuA our old form and tree will be display and when we click on menuB our newly created from and tree would be shown.

Post a Comment

7 Comments

  1. Hi,
    Can you plz help me in this. I inherit hr.attendance model and want new view and new form but i see two view the original one is on top and my new one is at the bottom. what is the problem with me can you plz help, thanks.

    ReplyDelete
    Replies
    1. Hey Umar... please check out this link may be its helped you in your scenario: http://learnopenerp.blogspot.com/2018/01/inheritance-in-models-and-views.html

      Delete
  2. I inherit hr.employee tree, I have two menus and I want to make two tree each different in one model. thank you

    ReplyDelete
  3. is it possible to make two different views from different models into one view. i have two models model.a & model.b and their tree views. i want to inherit data from the both models and make new tree view(this new tree view contain both models fields)

    ReplyDelete