Hi,
I'm using Odoo 17, and Im trying to trigger an XML-RPC Inventory Count Request for all of the items which are present at a certain warehouse location.
In my example, I've got:
- WH location: 'WH/Stock/Fridge1' with ID: 49
- Product IDs which are present at location with ID 49: [135, 164, 163, 177]
I now want to trigger an Inventory Count Request for the different products at that location, which should automatically pop-up in the Barcode App.
I was thinking of the following piece code, but it doesn't work.
The error message I get is: Error creating inventory request:
Can anyone point me in the right direction on how I should handle/fix this?
def request_inventory_count(location_id, product_ids):
try:
# Step 1: Create a new inventory adjustment
inventory_id = models.execute_kw(
ODOO_DB, uid, ODOO_PASSWORD,
'stock.inventory.adjustment',
'create', [{
'name': f'Inventory Request for Location {location_id}',
'location_ids': [(6, 0, [location_id])], # Add the location to the inventory adjustment
'state': 'draft', # Start in draft state
}]
)
print(f"Created inventory adjustment with ID {inventory_id} for location {location_id}")
# Step 2: Add products to the inventory adjustment
for product_id in product_ids:
# Add the product to the inventory adjustment
models.execute_kw(
ODOO_DB, uid, ODOO_PASSWORD,
'stock.inventory.adjustment.line', # Adjust line model if necessary
'create', [{
'inventory_id': inventory_id,
'product_id': product_id,
'location_id': location_id,
}]
)
print(f"Added product ID {product_id} to inventory adjustment {inventory_id}")
print(f"Inventory count requested for location {location_id}.")
except Exception as e:
print(f"Error creating inventory request: {e}")
location_id = 49 # Replace with the actual location ID
product_ids = [135, 164, 163, 177] # Replace with actual product IDs you want to count
request_inventory_count(location_id, product_ids)
Thank you in advance.
Cheers,
Gioti