Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
32856 Lượt xem

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
Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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




Ảnh đại diện
Huỷ bỏ

if i want to specific company so whats my query ?

Something odd happens using this. if you do it for two warehouses both results will be the same results as the first one. any ideas whats the problem?

Câu trả lời hay nhất

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 #change for your quantity field
           
print available_quantity


HTH

Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Câu trả lời hay nhất

This module will help you

https://www.odoo.com/apps/modules/10.0/product_qty_in_multi_warehouse/

Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks. But I have already solved.

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 6 16
2830
2
thg 3 15
5115
2
thg 7 22
5050
2
thg 12 20
2930
1
thg 10 17
3545