You are currently viewing Mastering Odoo Route Management: A Comprehensive Guide

Mastering Odoo Route Management: A Comprehensive Guide

Odoo is a powerful ERP platform that offers comprehensive tools for business management. Among its many features, Odoo Route Management is an essential component used to automate the flow of goods between locations in your business, be it warehouses, stores, or any other locations. By configuring routes and associating them with various products or processes, Odoo can help automate stock movements, shipments, and deliveries.

In this article, we’ll dive into Odoo Route Management and explore it with practical coding examples. These examples will help developers understand how to configure routes and integrate them into business processes in Odoo.

Also Read:

Understanding Odoo Route Management

Odoo Route Management are configurations that define how products are moved between different locations within warehouses or between warehouses and customers. A route typically involves operations like replenishment, internal transfer, drop-shipping, and make-to-order.

Key Concepts:

  1. Routes: Defines the rules and paths for the movement of stock.
  2. Operations: Actions associated with routes such as transferring goods between locations, ordering products from a supplier, etc.
  3. Warehouse Locations: The physical or virtual locations where products are stored.
  4. Stock Moves: The physical movement of products from one location to another.

Types of Routes:

  • Push Rule: Pushes products from one location to another (e.g., from stock to shipping).
  • Pull Rule: Pulls products into a location when they are needed (e.g., pulling from warehouse to sales order).
  • Drop Shipping: A route where a product is shipped directly from the vendor to the customer, bypassing the warehouse.
  • Make to Order: A route used for products that need to be manufactured or ordered upon receiving a sales order.

Basic Configuration Steps in Odoo Route Management

Before diving into code, let’s first understand how to configure routes within the Odoo UI.

  1. Enable Route Management:
    • Navigate to Inventory > Configuration > Settings.
    • Enable the “Routes” option under the Routes & Warehouse section.
  2. Create Routes:
    • Go to Inventory > Configuration > Routes.
    • Click the Create button to add a new route, specifying necessary information like Route Name (e.g., “Make to Order”) and defining applicable operations (e.g., Buy or Manufacture).

Once the routes are defined in the UI, you can use Python code to implement or customize the routes for specific products and automate the stock movement processes.

Coding Examples for Route Management in Odoo

1. Defining a Route in Python Code

To define routes programmatically, we need to interact with Odoo’s stock.location.route model. Routes can be linked to products and warehouse locations to automate stock movements.

Here is a Python example to create a new route in Odoo:

python

from odoo import models, fields

class RouteExample(models.Model):
_name = ‘stock.location.route’
_description = ‘Route Example’

name = fields.Char(string=‘Route Name’, required=True)
warehouse_id = fields.Many2one(‘stock.warehouse’, string=“Warehouse”)
action = fields.Selection([
(‘buy’, ‘Buy’),
(‘make_to_order’, ‘Make to Order’),
(‘transfer’, ‘Transfer’),
(‘pull’, ‘Pull’),
(‘push’, ‘Push’),
(‘drop_shipping’, ‘Drop Shipping’),
], string=‘Action’, required=True)

In the above code:

  • We define a custom model RouteExample that inherits from models.Model (the base model in Odoo).
  • We specify a route name and associate it with a warehouse.
  • The action field describes the type of action the route will take (buy, make-to-order, etc.).

2. Associating Routes with Products

Once the routes are defined, the next step is to associate them with specific products. This is done by adding routes in the product configuration. To do this programmatically, you can create a method to assign routes to products like so:

python
class ProductRoute(models.Model):
_inherit = 'product.template'
route_ids = fields.Many2many(‘stock.location.route’, string=‘Routes’)

def assign_route_to_product(self, route_id):
# Assign a specific route to a product
self.route_ids = [(4, route_id)]

In the above code:

  • route_ids field is used to associate a product with multiple routes.
  • assign_route_to_product is a method that allows assigning routes to a product. It uses the [(4, route_id)] syntax to add an existing route to a product.

3. Configuring Push and Pull Rules

In Odoo Route Management, routes often use push and pull rules to determine how stock is moved between locations. A push rule transfers stock from one location to another, while a pull rule pulls stock into a location when it’s needed (e.g., when a sales order is confirmed).

Here is an example to create a push rule and link it to a specific route:

python
class PushRuleExample(models.Model):
_name = 'stock.rule'
_description = 'Push Rule Example'
name = fields.Char(string=‘Rule Name’)
route_id = fields.Many2one(‘stock.location.route’, string=‘Route’)
action = fields.Selection([
(‘push’, ‘Push’),
(‘pull’, ‘Pull’),
], string=‘Action’, required=True)
location_id = fields.Many2one(‘stock.location’, string=‘Source Location’)
location_dest_id = fields.Many2one(‘stock.location’, string=‘Destination Location’)

def create_push_rule(self):
rule = self.create({
‘name’: ‘Push from Stock to Shipping’,
‘route_id’: self.route_id.id, # Link to a route
‘action’: ‘push’,
‘location_id’: self.location_id.id, # Stock location
‘location_dest_id’: self.location_dest_id.id, # Shipping location
})
return rule

In this example:

  • stock.rule is used to define push and pull rules for stock movement.
  • The create_push_rule method creates a push rule where products are moved from a stock location to a shipping location.

4. Automating Stock Movements Based on Routes

After defining routes and rules, you can automate the stock movement process based on actions triggered by sales or purchase orders. For example, when a sales order is confirmed, you can trigger a stock move to fulfill the order.

Here’s an example that automatically creates a stock move when an order is confirmed:

python
class SaleOrder(models.Model):
_inherit = 'sale.order'
def action_confirm(self):
res = super(SaleOrder, self).action_confirm()
for order in self:
# Create stock moves based on order lines and routes
for line in order.order_line:
# Check product’s route
if line.product_id.route_ids:
# Create stock move for each line based on the product route
stock_move = self.env[‘stock.move’].create({
‘name’: line.product_id.name,
‘product_id’: line.product_id.id,
‘product_uom’: line.product_uom.id,
‘product_uom_qty’: line.product_uom_qty,
‘location_id’: order.warehouse_id.lot_stock_id.id, # Stock location
‘location_dest_id’: order.partner_id.property_stock_customer.id, # Customer location
‘route_ids’: [(4, line.product_id.route_ids.id)], # Link to route
})
stock_move.action_confirm() # Confirm stock move
return res

In this example:

  • The action_confirm method of the sale order is overridden to automatically create a stock move when the order is confirmed.
  • The route_ids field of the product determines the specific route to be followed for stock movement.

Conclusion

Odoo Route Management system allows businesses to automate the flow of products through various locations, ensuring efficient inventory management, order fulfillment, and supply chain operations. By using push and pull rules, route-based stock movements, and product-route associations, Odoo can automate many manual tasks, helping businesses save time and reduce errors.

In this article, we have walked through how to define routes, link them to products, set up push/pull rules, and automate stock movements using Python code. With these capabilities, you can take full advantage of Odoo Route Management system to optimize your operations and improve efficiency across your business.

For more information about the Odoo Route Management: visit this link.

If you want to Free Trail Zoho, click on this link.

Yasir Baig

My name is Mirza Yasir Baig. As an experienced content writer and web developer, I specialize in creating impactful digital experiences. With expertise in WordPress programming and the MERN stack, I have built and managed various web platforms, including the different a dedicated resource for both Pakistani and international students seeking quality courses and training programs. My work is driven by a passion for education and technology, ensuring that content is not only engaging but also optimized for search engines (SEO) to reach a wider audience.

Leave a Reply