In order to compute the stock levels in a given location for all the products, you need to perform the following steps:
- Create a model class extending product.product:
class ProductProduct(models.Model): _inherit = 'product.product'
- Add a method called stock_in_location():
@api.model def stock_in_location(self, location):
- In the method, get a product.product recordset with a context modified, as follows:
product_in_loc = self.with_context( location=location.id, active_test=False )
- Search all products:
all_products = product_in_loc.search([])
- Create an array with the product name and stock level of all products present in the specified location:
stock_levels = [] for product in all_products: if product.qty_available: stock_levels.append((product.name, product.qty_available)) return stock_levels