Search code examples
odooopenerp-7openerp-8

How to redirect from one form view to another in odoo?


Even though button appears it does not redirect me anywhere.I want first button to redirect to sale.order form view (id 605) which contains discount and second button to sale2.order form view (id 575) which does not contain any discount to items.Should i do anything in python code or just modify my xml code?

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

    <record id="view3_order_form" model="ir.ui.view">
        <field name="name">sale3.order.form</field>
        <field name="model">sale.order</field>
        <field name="arch" type="xml">
            <form string="Sales Order">
                <h1>Selection Panel</h1>
                    <button name="redirection1" string="Discount" type="action" class="oe_highlight"/>
                    <button name="redirection2" string="No Discount" type="action" class="oe_highlight"/>
            </form>
        </field>
    </record>

    <record id="action3_orders" model="ir.actions.act_window">
        <field name="name">Sales3 Orders</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">sale.order</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
    </record>

    <record id="redirection1" model="ir.actions.act_window">
        <field name="name">Redirection_to_discount</field>
        <field name="res_model">sale.order</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="res_id">605</field>
        <field name="target">current</field>
    </record>

    <record id="redirection2" model="ir.actions.act_window">
        <field name="name">Redirection_to_no_discount</field>
        <field name="res_model">sale.order</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="res_id">575</field>
        <field name="target">current</field>
    </record>

</data>
</openerp>

Solution

  • The name for action button should actually be action's numeric id, and not action's name. Of course in reality it would be much better to use the name. To do that use the printf syntax - %(action_name)d instead of action_name. This way the name will later be replaced with a numeric id:

    <button name="%(redirection1)d" string="Discount" type="action" class="oe_highlight"/>
    <button name="%(redirection2)d" string="No Discount" type="action" class="oe_highlight"/>