Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
1229 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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"

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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​ ?

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 25
490
3
thg 9 24
4763
0
thg 7 16
2969
2
thg 8 15
7473
0
thg 12 24
1706