跳至內容
選單
此問題已被標幟
2 回覆
1238 瀏覽次數

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

頭像
捨棄
作者 最佳答案

The last part of the error message got filtered out, because it started with a <

Here below is the full error message:

Error creating inventory request: Fault 2: "Object stock.inventory.adjustment doesn't exist"

頭像
捨棄
最佳答案

The error message ` Error creating inventory request` is from your exception handling, not from Odoo.
Can you share what Odoo catch on the error by printing the value from variable e​ ?

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
7月 25
490
3
9月 24
4764
0
7月 16
2970
2
8月 15
7474
0
12月 24
1707