I'm trying to update stock in code, but I need the location ID. I have two questions:
1. How do I find the ID of my stock location?
2. How do I find this ID in code using the name or something, like find the id of "US Michigan Warehouse" location, or in code can I only strictly put ID?
Thanks.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
You can basically find out any ID, if you activate developer mode. Settings > Developer Tools > Activate the developer mode. Then go to your warehouse, or location and click on the debug symbol and then go to View metadata. Here you find the ID you need. See below to find the ID of a warehouse, but you can repeat this step for locations as well. Just select the location and then repeat the following procedure.
I hope this helps!
Hi,
Hard coding the id inside the code or searching with the name of location inside the code is also not a recommended way. The ID of the location can be changed from db to db and the name can be edited and changed at any time from the user interface.
If your name remains same, assuming so, you can get the location id as follows:
location_id = self.env['stock.location'].search([('name', '=', 'US Michigan Warehouse')], limit=1)
To know more about the search orm method: Odoo Search ORM Method
Depending on your workflow and configuration, it is recommended to get location in more robust way, may be from the user configuration or based on some settings.
Thanks
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
2
Jun 25
|
477 | ||
|
1
May 25
|
96 | ||
|
0
May 25
|
528 | ||
|
1
May 25
|
757 | ||
|
1
May 25
|
905 |