如何获得可用数量的产品(Odoo v8和v9) [英] How to get products available quantity (Odoo v8 and v9)

查看:73
本文介绍了如何获得可用数量的产品(Odoo v8和v9)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从odoo库存中获取可用数量的产品.

I need to get products available quantity from odoo stock.

我有几种模型stock_quant,stock_move,stock_location.

There are several models I stock_quant, stock_move, stock_location.

我想要实现的是两件事:

What I am trying to achieve are two things:

  1. 产品总可用数量
  2. 根据位置提供的产品可用数量

有人可以引导我吗?

推荐答案

与库存相关的字段在产品中定义(功能字段),您可以直接从产品中获取所有仓库/地点或单个地点/仓库的库存.

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.

示例:

对于所有仓库/地点

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

对于单个地点/仓库(WAREHOUSE_ID/LOCATION_ID应替换为实际ID)

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

其他字段也在那里.

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.

有关更多详细信息,您可以在库存模块中引用product.py.

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

解决方案:

@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

这篇关于如何获得可用数量的产品(Odoo v8和v9)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆