Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
1237 Представления

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

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
июл. 25
490
3
сент. 24
4764
0
июл. 16
2970
2
авг. 15
7474
0
дек. 24
1707