Configure a button in a form to open a view

Asked by Carlos Almeida

Hi,

How can I configure a button in a form to open a view.
For example a button to open directly the partners view.

Thanks,

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Web Client Edit question
Assignee:
No assignee Edit question
Solved by:
Nicolas DS
Solved:
Last query:
Last reply:
Revision history for this message
Carlos Almeida (cmsa) said :
#1

And yes I search in documentation but don't find any example :(

Revision history for this message
Cristian Salamea (ovnicraft) said :
#2

in method linked with button you must return a dict with key 'view_id':your view_id

Revision history for this message
Carlos Almeida (cmsa) said :
#3

Can you show me an example please. (view xml)
Thanks in advance,

Revision history for this message
Best Nicolas DS (zyphos) said :
#4

If you want to open a new tab you should use action:
in xml:
<!-- The form view with the button -->
<record id="view_name_id" model="ir.ui.view">
    <field name="name">myobjet.form</field>
    <field name="model">myobject</field>
    <field name="type">form</field>
    <field name="arch" type="xml">
        <form string="My Object">
           ...
           <button type='action' name='action_open_partners' />
           ...
        </form>
    </field>
</record>

<!-- The action that will be triggered by the button. -->
<record id="action_open_partners" model="ir.actions.act_window">
    <field name="name">Partners</field>
    <field name="res_model">res.partner</field>
    <field name="view_type">tree</field><!-- Optional: Show the tree view (default: form) -->
    <field name="view_mode">tree</field><!-- Optional: Only allow the tree view (default: tree,form) -->
    <field name="target">new</field><!-- Optional: Open in new tab (default: current) -->
</record>

Revision history for this message
Carlos Almeida (cmsa) said :
#5

Thanks Nicolas DS, that solved my question.