Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
554 views
in Technique[技术] by (71.8m points)

python 2.7 - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...