I need to get the quantity available for a products in odoo stock. From this question, How to get products available quantity (Odoo v8 and v9) I know I can get the quantities by warehouse and by location as follows.
product = self.env['product.product'].browse(PRODUCT_ID)
available_qty = product.with_context({'warehouse' : WAREHOUSE_ID}).qty_available
available_qty = product.with_context({'location' : LOCATION_ID}).qty_available
What I want to achieve is the stock available at a specific date. On checking the code inside stock/product.py, I see it should be possible to pass 'from_date' and 'to_date' in context the same way you can pass location and warehouse id. Doing this as follows doesn't seem to work.
available_qty = product.with_context({'to_date' : '2017-01-01 00:00'}).qty_available
Any ideas on how I can get the available_qty by passing the date?