0

I am trying to fetch all stock locations which are under a specific warehouse in Odoo 15. I tried the below code.

locations_dd.append(self.env['stock.location'].search([('warehouse_id','=',i)]).ids)

But I am getting the below error:

ERROR odoo15ee odoo.osv.expression: Non-stored field stock.location.warehouse_id cannot be searched.

How can I solve this?

Kenly
  • 24,317
  • 7
  • 44
  • 60
KbiR
  • 4,047
  • 6
  • 37
  • 103

1 Answers1

1

warehouse_id is a non-stored computed field, you can't use it in the search domain.

You can use the stock location location_id field (which is the parent location) and the warehouse view location field (view_location_id) to get all warehouse locations.

Example:

location_ids = self.env['stock.location'].search([('location_id', 'child_of', warehouse_id.view_location_id.id)])
Kenly
  • 24,317
  • 7
  • 44
  • 60