Stock levels SQL request

For BI purpose, I need to get current quantity and virtual quantity for each variant, by stock location.
I can see those quantities in Tryton in products by location screen which are calculated in get_quantity function, but before trying to reinvent the wheel, I would like to know if someone already worked on a SQL request able to calculate those stock levels by product/location.
Thanks