To add an additional menu in action dropdown list on tree view, we need to register “ir.actions.server” and “ir.values” on the qweb/xml 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 bellow 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'}) ...
Restart odoo and upgrade your module, you’ll have now cancel menu on your sales order tree view.