Search code examples
python-3.xodooodoo-10odoo-9odoo-11

Can i get warehouse_id from location_id in odoo 10,11


Is it possible to get warehouse_id from location_id in odoo. thanks.


Solution

  • Odoo 10 and 11

    location = self.env['stock.location'].browse(1)  # or any other location
    warehouse = location.get_warehouse()
    

    Code for get_warehouse()

    @api.multi
    @api.returns('stock.warehouse', lambda value: value.id)
    def get_warehouse(self):
        """ Returns warehouse id of warehouse that contains location """
        return self.env['stock.warehouse'].search([
            ('view_location_id.parent_left', '<=', self.parent_left),
            ('view_location_id.parent_right', '>=', self.parent_left)], limit=1)