DEV Community

Fabian Anguiano
Fabian Anguiano

Posted on

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

Top comments (0)