Add menu in dropdown list action tree view – Odoo 9

To add a menu in action dropdown list on tree view, we need to register first “ir.actions.server” and “ir.values” on the qweb file as follow. Note that code field name is using old odoo python API.

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

        ...

        <record id="action_cancel_request" model="ir.actions.server">
            <field name="name">Cancel</field>
            <field name="type">ir.actions.server</field>
            <field name="model_id" ref="sale.model_sale_order" />
            <field name="state">code</field>
            <field name="binding_model_id" ref="sale.model_sale_order" />
            <field name="code">action = self.action_cancel(cr, uid, context.get('active_ids', []), context=context)</field>
        </record>

        <record id="cancel_action_menu" model="ir.values">
            <field eval="'client_action_multi'" name="key2"/>
            <field eval="'sale.order'" name="model"/>
            <field name="name">Cancel</field>
            <field eval="'ir.actions.server,%d'%action_cancel_request" name="value"/>
        </record>

        ....

    </data>
</openerp>

In your sale order model create the method as above with Odoo new API.

    ...

    @api.multi
    def action_cancel(self):
        if self.env.context.get('active_ids', False):
            sale_order_ids = self.browse(self.env.context.get('active_ids'))
            for sale_order in sale_order_ids:
                sale_order.update({'state': 'cancel'})

    ...

How useful was this post?

Average rating / 5. Vote count:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.