我可以从odoo 10,11中的location_id获得warehouse_id

时间:2018-04-13 05:24:29

标签: python-3.x odoo odoo-10 odoo-9 odoo-11

是否可以从warehouse_id获取location_id。 感谢。

1 个答案:

答案 0 :(得分:3)

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)