How to do it...

In order to compute the stock levels in a given location for all the products, you need to perform the following steps:

  1. Create a model class extending product.product:
class ProductProduct(models.Model): 
    _inherit = 'product.product' 
  1. Add a method called stock_in_location():
    @api.model 
    def stock_in_location(self, location): 
  1. 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 
    ) 
  1. Search all products:
    all_products = product_in_loc.search([])
  1. 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
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.253.62