Skip to Content

Sales Order Automations (Part Three): Automate Stock Reservation


Recap of Part 1 & 2

In the first two parts of this series, we learned how to use Automated Actions in Odoo to:

  • Part 1: Automatically confirm sales orders for VIP customers. Click here.
  • Part 2: Send automated email notifications to the sales team. Click here.

Now, we will complete the sales workflow by setting up an action to automatically trigger stock reservation and validation as soon as a sales order is confirmed. This step is crucial for ensuring products are immediately prepared for shipping and fulfilling the order quickly.

Step 1: Configure the Automated Action

First, you'll need to create a new Automated Action or modify the one from Part 2.

  • Go to Settings > Technical > Automated Actions.
  • Click Create.

Step 2: Define Basic Settings

This action will be triggered by a change in the sales order status.

  • Name: Automate Stock Reservation
  • Model: Sales Order (sale.order)
  • Trigger: On Update
  • Apply On: Orders where the state changes to sale. The domain filter for this is: 
[('state', '=', 'sale')]
  • Action To Do: Execute Python Code

Step 3: Add Python Code

Add the following code snippet to the Python Code field. This script looks for any related stock transfers (picking) associated with the confirmed sales order and validates them, which effectively moves the stock.

Python

if record.picking_ids:
    for picking in record.picking_ids:
        if picking.state in ['assigned', 'draft']:
            picking.button_validate()


Step 4: Save and Test the Automation

  • Save the automated action.
  • Create a new sales order, and once you confirm it, the related stock transfer will be automatically validated.
  • Check the corresponding Delivery record in the Inventory app to confirm that its status has changed to Done. You should also see that the product has been reserved and moved from your stock.


Conclusion

By implementing this final step, you have created a fully automated sales workflow in Odoo. Your system will now handle the entire process from a VIP customer's order to confirming the sale, notifying your team, and reserving the stock—all without manual intervention.

Stay tuned for Part 4, where we will learn how to automatically create and send an invoice once the delivery is completed!


Sales Order Automations (Part Two): How to Send Email Notifications to the Sales Team