There is a function in product.product called get_product_available
. You can get the stock value in location by passing the location id in context. So you can modify your code as:
def product_qty_by_location(self, cr, uid, product_id, warehouse_stock_location, context=None):
if context is None:
context = {}
product_pool = self.pool.get('product.product')
context.update({'states': ('done',), 'what': ('in', 'out'), 'location': warehouse_stock_location})
result = product_pool.get_product_available(cr, uid, [product_id], context=context)
qty = result.get(product_id, 0.00)
return qty
You can also get the stock level of product based on warehouse by passing warehouse_id insted of location_id as:
context.update({'states': ('done',), 'what': ('in', 'out'), 'warehouse': <warehouse_id>})