Bulk Updating Sale Order Status Based on Customer in Odoo 17 ERP 
In Odoo, we can enhance sales order management by adding a menu that allows bulk updating of sale order states based on the selected customer.…

In Odoo, we can enhance sales order management by adding a menu that allows bulk updating of sale order states based on the selected customer. This feature simplifies order processing by fetching all orders/ quotations for a customer and enabling bulk confirmation of orders. This also can be used for any other action that you want to perform in bulk for Sales orders.

Step 1: Adding a Menu for Bulk Updating Sale Orders

To implement this, we need to create a submenu under the Orders menu in the Odoo Sales module. The form view for this menu will contain:

  • A Many2one field to select a customer from the dropdown.
  • A Many2many field to list sale orders associated with the selected customer.
  • Two action buttons:
    • Submit: Fetches sale orders in the “Quotation Sent” state for the selected customer.
    • Confirm: Confirms the fetched sale orders.

Below is the XML code to define the menu, action, and form view:

xml

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

    <!– Define the Form View for Sale Orders by Customer –>
    <record id="sale_order_by_customer_form_view" model="ir.ui.view">
        <field name="name">Sale Order Customer Form View</field>
        <field name="model">sale.order.customer</field>
        <field name="arch" type="xml">
            <form string="Quotation Sent" create="False" delete="False">
                <header>
                    <button string="CONFIRM" name="confirm_sale_order" type="object" class="oe_highlight"/>
                </header>
                <sheet>
                    <label for="customer_id">Customer: </label>
                    <field name="customer_id" string="Customer:"/>
                    <button name="get_sale_orders" string=’SUBMIT’ type=’object’/>
                    <field name="sale_order_ids">
                        <tree>
                            <field name="name" readonly="True"/>
                            <field name="create_date" readonly="True"/>
                            <field name="partner_id" readonly="True"/>
                            <field name="user_id" readonly="True"/>
                            <field name="company_id" readonly="True"/>
                            <field name="amount_total" readonly="True"/>
                            <field name="state" readonly="True"/>
                        </tree>
                    </field>
                </sheet>
            </form>
        </field>
    </record>

    <!– Define Action for the New Menu –>
    <record id="sale_order_by_customer_action" model="ir.actions.act_window">
        <field name="name">Sale Order By Customer</field>
        <field name="res_model">sale.order.customer</field>
        <field name="view_id" ref="sale_order_by_customer_form_view"/>
        <field name="view_mode">form</field>
    </record>

    <!– Add Menu Item under Sales Orders –>
    <menuitem
        id="sale_order_by_customer"
        name="Orders By Customer"
        parent="sale.sale_order_menu"
        action="sale_order_by_customer_action"
        sequence="50"/>
</odoo>

Explanation of the XML Configuration

  • Menuitem (Orders By Customer): Added under the Orders menu in Odoo.
  • Form View: Displays a dropdown for selecting a customer and a table for listing their sales orders.
  • Buttons:
    • SUBMIT: Fetches sale orders for the selected customer.
    • CONFIRM: Confirms the selected sale orders in bulk.

Step 2: Defining the Model and Methods in Python

We now create a model (sale.order.customer) to manage the sale order selection and confirmation process.

python

# -*- coding: utf-8 -*-
import logging
from odoo import models, fields, api, _
_logger = logging.getLogger(__name__)
class SaleOrderCustomerSearch(models.Model):
_name = ‘sale.order.customer’
_description = ‘Sale Order Customer’
name = fields.Char(string="Sale Order By Customer")
customer_id = fields.Many2one(‘res.partner’, string="Customer")
sale_order_ids = fields.Many2many(
comodel_name=’sale.order’,
relation=’sale_order_customer_rel’,
column1=’partner_id’,
column2=’sale_id’,
string="Sale Orders"
)
def get_sale_orders(self):
"""Fetches all sale orders in ‘Quotation Sent’ state for the selected customer."""
self.sale_order_ids = []
if self.customer_id:
sale_orders = self.env[‘sale.order’].search([
(‘partner_id’, ‘=’, self.customer_id.id),
(‘state’, ‘=’, ‘sent’)
])
self.sale_order_ids = sale_orders
def confirm_sale_order(self):
"""Confirms all fetched sale orders in bulk."""
for order in self.sale_order_ids:
order.action_confirm()
self.get_sale_orders() # Refresh the list after confirmation
def default_get(self, fields):
"""Sets the default name for the record."""
res = super(SaleOrderCustomerSearch, self).default_get(fields)
res[‘name’] = ‘Sale Order By Customer’
return res

Explanation of the Python Code

  • get_sale_orders():
    • Fetches sale orders in the “Quotation Sent” (sent) state for the selected customer.
    • Assigns them to the sale_order_ids field.
  • confirm_sale_order():
    • Confirms all fetched sale orders in one click.
    • Uses Odoo’s default action_confirm() method from the Sales module.
  • default_get():
    • Sets a default name for the record.

Step 3: Setting Up Access Rights

To ensure only authorized users can access this functionality, add an entry in the ir.model.access.csv file:

csv

access_sale_order_customer,sale_order_customer,model_sale_order_customer,base.group_user,1,1,1,1

Explanation of Access Rights

  • model_sale_order_customer: Refers to the new model we created.
  • base.group_user: Grants access to all standard users.
  • 1,1,1,1: Provides full access (Read, Write, Create, Delete).

Step 4: Testing the Feature in Odoo UI

  1. Navigate to Sales → Orders By Customer (New menu added).
  2. Select a Customer from the dropdown.
  3. Click “Submit” to fetch all sale orders in the “Quotation Sent” state.
  4. Review the fetched orders displayed in a table.
  5. Click “Confirm” to bulk confirm all fetched orders.
  6. Navigate back to the Quotations menu to verify the updated order statuses.

Conclusion

This Odoo enhancement streamlines bulk sale order processing by:

  • Enabling users to fetch sale orders based on customers.
  • Allowing bulk confirmation of multiple sale orders in one click.
  • Reducing manual work and improving efficiency in the sales workflow.

With this feature, Odoo users can manage sales orders more effectively, making the sales process smoother and more automated.