Bài học

Bài học thuộc : Odoo tip Trạng thái bài học : Chưa hoàn thành

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.

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.


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>

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 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" />

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.


Gắn sao :  

Tác giả : admin admin