This question has been flagged
3 Replies
3629 Views

in a custom module we have different detail-View-definitions and also 2 different tree views

how can i achieve that if i use the second tree-view, selecting an item within this tree-view should target to an alternative detail-view.


Edit: added sample code


<record model="ir.ui.view" id="dummy_form_view">
<field name="name">dummy.form</field>
<field name="model">x_dummy.dummy</field>
<field name="type">form</field>
<field name="priority" eval="13"/>
<field name="arch" type="xml">

<form string="dummy" create="false" edit="false" delete="false">
<sheet>
<group>
<field name="name"  nolabel="1"/>
</group>
</sheet>
</form>
</field>
</record>

<record model="ir.ui.view" id="dummy_form_view2">
<field name="name">dummy.form</field>
<field name="model">x_dummy.dummy</field>
<field name="type">form</field>
<field name="priority" eval="15"/>
<field name="arch" type="xml">
<form string="dummy" delete="false" duplicate="false">
<group>
<field name="name2"  />
</group>
                                    </form>
</field>
</record>


<record model="ir.ui.view" id="dummy_tree_view">
<field name="name">dummy.tree</field>
<field name="model">x_dummy.dummy</field>
<field name="arch" type="xml">
<tree>
<field name="name" context="{'form_view_ref': 'x_dummy.dummy_form_view2'}"/>
</tree>
</field>
</record>


my goal is that the treeview opens dummy_form_view2 but it opens still the first view

Avatar
Discard

Hope you need this: https://goo.gl/Baw9Zt

Author

@Sehrish: no i do not want to reedirect to a treeview. i want to link within 2 different treeviews to different form-views

Best Answer

Hi,

use the context in your action. A similar example from the 'product' module:

'tree_view_ref': 'product.product_packaging_tree_view2', 'form_view_ref':'product.product_packaging_form_view2'

In such a way the action will lead not to default form, tree, but to predefined ones.

UPDATE

You should add context not to field (name), but to action. Thus, you need 2 have to actions for different menu items. One without context - for default form and tree, another with specified context views. Example:

    <record id="action_with_default_form" model="ir.actions.act_window">
        <field name="name">Default form view</field>
        <field name="res_model">x_dummy.dummy</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="context">{}</field>
    </record> 
    <record id="action_with_specified_form" model="ir.actions.act_window">
        <field name="name">Specified form view</field>
        <field name="res_model">x_dummy.dummy</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="context">{'form_view_ref':'YOURMODULE.dummy_form_view2'}</field>
    </record> 


Avatar
Discard
Author

i added sample code to my initial Post. Adding context= did not help

Hi, you added context to a wrong place. Look at my updated answer

Author

thanks this works