In Odoo we need to perform actions like delete, duplicate, archive etc. to one or multiple records. For this process we are using action menu in the form view and tree view. Action menu inside a form view is only applicable for the current record. For perform the action for multiple records we are using the action menu in the tree view. Here in the blog we are going to discuss about how to add a new menu inside the action drop down menu.

Action drop down menu in sale order form view




Action drop down menu in sale order tree view




Now we are going to add a new menu inside the action menu to cancel one or multiple sale orders. So first we creating a wizard for confirming the cancellation of sale orders.

Following is the python file for the wizard

from odoo import api, fields, models, _
from odoo.exceptions import UserError

class MultipleOrderCancel(models.TransientModel):
    _name = "multiple.order.cancel"
    _description = "Cancel Multiple Orders"

    def cancel_multiple_orders(self):
        for record in self._context.get('active_ids'):
            sale_order = self.env[self._context.get('active_model')].browse(record)
            if sale_order.state == 'done':
                raise UserError(_("You cannot cancel the locked orders"))
            else:
                sale_order.action_cancel()


After creating the python file we need to create view for the wizard.

<record id="view_cancel_multiple_orders_form" model="ir.ui.view">
    <field name="name">multiple.order.cancel.form</field>
    <field name="model">multiple.order.cancel</field>
    <field name="arch" type="xml">
        <form string="Cancel Orders">
            <p>
                Are you sure you want to cancel selected orders ?
            </p>
            <footer>
                <button name="cancel_multiple_orders" string="Confirm" type="object" class="btn- primary"/>
                <button string="Cancel" class="btn-default" special="cancel"/>
            </footer>
        </form>
    </field>
</record>


Now we are going to add the menu for cancel orders.

<act_window name="Cancel Order"
    id="action_cancel_order"
    res_model="multiple.order.cancel"
    binding_model="sale.order"
    binding_views="list"
    view_mode="form"
    target="new"
/>


In the above code name is the menu name which shown inside the action menu, id is the id of the action window, binding_model is the model name in which model we are adding the action and binding_views is the view type in which view we are adding the button. Here the binding_model is sale.order and the binding_views is list. So this action will be in sale.order model and it will show inside the tree view. We can set it only for form view and for both form view and tree view. The binding_views="form" will show in the form view only and binding_views="form,list" will show in the form view and tree view.

Cancel Order button in sale order tree view



By clicking the Cancel Order menu we can see the wizard which we are created.




From the wizard click Confirm button for cancelling multiple orders. Below is the image of cancelled sale orders.




This is how we are adding a new menu inside an action drop down menu.


If you wish to have the latest updates from us, you may follow us on