Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get products available quantity (Odoo v8 and v9)

I need to get products available quantity from odoo stock.

There are several models I stock_quant, stock_move, stock_location.

What I am trying to achieve are two things:

  1. Products total available quantity
  2. Products available quantity based on location

Can anyone please guide me?

like image 954
Tanzil Khan Avatar asked Oct 24 '16 04:10

Tanzil Khan


People also ask

What is quantity multiple in Odoo?

multiple quantity is used when the product must be ordered in multiple units because your supplier does not sell single units for instance, or because you want to. the unit specified on the product form.

How is forecasted quantity calculated Odoo?

Forecasted quantity = Onhand quantity - outgoing shipment product quantity + incoming shipment product quantity.

Where is product category in Odoo?

Clicking on Product Category we can find the product categories listed out. These are the pre-configured product categories. The categories here are consumables, expenses, Rental, Internal, Saleable, Deliveries, etc.

What is product packaging in Odoo?

Functional Odoo 15. Product packaging is a valuable tool both for business and the client. The company can reduce shipping charges, delivery charges, and many more and help sell products at a low margin. For the customer, it is worth their money, and they have the opportunity to gain a discount.


1 Answers

Stock related fields are defines in products (functional field) and directly from the product you can get the stock for all warehouses / locations or for individual location / warehouse.

Example:

For all warehouses / locations

product = self.env['product.product'].browse(PRODUCT_ID)
available_qty = product.qty_available

For individual location / warehouse (WAREHOUSE_ID / LOCATION_ID should be replaced by actual id)

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

Other fields are also there.

Forecasted Stock => virtual_available
Incoming Stock => incoming
Outgoing Stock => outgoing

You can access all those fields in similar manner. If you will not pass any warehouse / location in context then it will returns the stock of the all warehouses together.

For more details you may refer product.py in stock module.

Solution:

@api.onchange('product_id','source_location') 
def product_qty_location_check(self): 
    if self.product_id and self.source_location: 
        product = self.product_id
        available_qty = product.with_context({'location' : self.source_location.id}).qty_‌​available 
        print available_qty
like image 124
Emipro Technologies Pvt. Ltd. Avatar answered Oct 10 '22 15:10

Emipro Technologies Pvt. Ltd.