我可以在 odoo 10,11 中从 location_id 得到 warehouse_id

Can i get warehouse_id from location_id in odoo 10,11

是否有可能在 odoo 中从 location_id 获取 warehouse_id。 谢谢。

Odoo 10 和 11

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

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)