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 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
1# -*- coding: utf-8 -*-2import logging3from odoo import models, fields, api, _4_logger = logging.getLogger(__name__)5class SaleOrderCustomerSearch(models.Model):6 _name = 'sale.order.customer'7 _description = 'Sale Order Customer'8 name = fields.Char(string="Sale Order By Customer")9 customer_id = fields.Many2one('res.partner', string="Customer")10 sale_order_ids = fields.Many2many(11 comodel_name='sale.order',12 relation='sale_order_customer_rel',13 column1='partner_id',14 column2='sale_id',15 string="Sale Orders"16 )17 def get_sale_orders(self):18 """Fetches all sale orders in 'Quotation Sent' state for the selected customer."""19 self.sale_order_ids = []20 if self.customer_id:21 sale_orders = self.env['sale.order'].search([22 ('partner_id', '=', self.customer_id.id),23 ('state', '=', 'sent')24 ])25 self.sale_order_ids = sale_orders26 def confirm_sale_order(self):27 """Confirms all fetched sale orders in bulk."""28 for order in self.sale_order_ids:29 order.action_confirm()30 self.get_sale_orders() # Refresh the list after confirmation31 def default_get(self, fields):32 """Sets the default name for the record."""33 res = super(SaleOrderCustomerSearch, self).default_get(fields)34 res['name'] = 'Sale Order By Customer'35 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
1access_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
- Navigate to Sales → Orders By Customer (New menu added).
- Select a Customer from the dropdown.
- Click "Submit" to fetch all sale orders in the "Quotation Sent" state.
- Review the fetched orders displayed in a table.
- Click "Confirm" to bulk confirm all fetched orders.
- 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.







