是否有可能从warehouse_id
获得location_id
。谢谢。
Odoo 10和11
location = self.env['stock.location'].browse(1) # or any other location
warehouse = location.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)