Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to get product quantity

By
Md. Tanzilul Hasan Khan
on 10/23/16, 3:09 AM 238 views

I need to get product quantity on product onchange. There is a model stock_quant, which records all quantity activity.

How can I get the available quantity of the product? I am writing following function and getting stock_quantity lines but not sure how to filter out the available quantity - 

    @api.multi    
    @api.onchange('product_id')
    def product_location_change(self):
        if self.product_id:
            stock_qty_obj = self.env['stock.quant']
            stock_qty_lines = stock_qty_obj.search([['product_id', '=', self.product_id.id]])
            print stock_qty_lines
             # TODO: GET AVAILABLE QUANTITY OF THE PRODUCT
0

For All Warehouse this is how the quantity can be checked:

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

For specific warehouse/location:

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:

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

I added necessary quantity to my function.


More details are here - http://stackoverflow.com/questions/40210605/how-to-get-products-available-quantity-odoo-v8-and-v9




0
Jaime Vasquez
On 10/23/16, 3:50 PM

Add a loop to the stock lines:

def product_location_change(self):
        if self.product_id:
            stock_qty_obj = self.env['stock.quant']                       
stock_qty_lines = stock_qty_obj.search([['product_id', '=', self.product_id.id]])
            print stock_qty_lines           
# TODO: GET AVAILABLE QUANTITY OF THE PRODUCT               

available_quantity = 0           
for row in stock_qty_lines:
available_quantity += row.quantity #chnage for your quantity field
           
print available_quantity


HTH

I am not asking to sum up my models line item. I know this already.

Want to find out the product quantity from stock_qty or stock_move table with locations.

Md. Tanzilul Hasan Khan
on 10/23/16, 11:46 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/23/16, 3:09 AM
Seen: 238 times
Last updated: 11/15/16, 1:26 AM