DEV Community

Fabian Anguiano
Fabian Anguiano

Posted on

1

Updating Odoo Inventory By Lots

Odoo inventory management is huge challenge. Handling 1-20 products ? No problem. Handling 1000-20000? We have a problem.

In this article, I am going to cover how to update inventory of a specific LOT.

I have a repo on the bottom of this page.

Updating inventory based on LOT’s has a couple of advantages, but for this case I am focused on speed. Lets get started.

  1. Get the ID of all locations where the LOT is located.
  2. Loop and get all the info we need.
  3. Overwrite the locations.

1. Get every location where the lot is located.

lotty= ‘iamalotid1234’

 lotty_product_location = models.execute_kw(db, uid, password, 'stock.quant', 'search_read', [['&', ['lot_id', '=',lotty],['on_hand','=',True]]])

Enter fullscreen mode Exit fullscreen mode

Lets break this down.

The script does two things.

Searches for ‘stock.quant’, that has a lot_id of ‘lotty’ and the ‘on_hand’ is true.

2. Lets loop and clean up some data

 for i in lotty_product_location:
        print("{0} - {1} - {2}".format(i['location_id'] 
              [1],i['product_id'][1],i['quantity']))

Enter fullscreen mode Exit fullscreen mode

3. Okay the data looks clean, lets over write everything to 0.

update_qty = models.execute_kw(db, uid, password, 'stock.quant', 'write', [[lotty_product_location[0]['id']], {'available_quantity': '0','quantity': '0'}])

Enter fullscreen mode Exit fullscreen mode

We can change to quantity to something else, but for now lets do 0 to see if our inventory is update.

NOTE: You need to update both 'available_quantity' and 'quantity'

DONE

We can get fancy and add in some more filtering and logic but for now we can updated all inventory based on the lots.

In the future I will make some more complex scripts, something like update all inventory if the quantity is x amount and the product is a certain product.

https://github.com/thetrebelcc/Odoo_lot_inventory_updates

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry 👀

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay