首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何获取单个库存的产品可用数量(Odoo11)

如何获取单个库存的产品可用数量(Odoo11)
EN

Stack Overflow用户
提问于 2019-03-27 07:22:29
回答 1查看 1.1K关注 0票数 0

我正在使用odoo11(python3)并开发一个自定义模块。

我想为个人库存获得产品数量(手工或预测)。

我只是选择任何一个单独的库存,并显示产品的数量为这个仓库。实际上,我的目标是两件事1.产品总可用量2.基于位置的产品可用数量--这是我的代码

代码语言:javascript
复制
class Threshold(models.Model):
    _name="threshold.threshold"
    main_location=fields.Many2many("stock.warehouse", string="Main Location")
    product=fields.Many2many("product.template", string="Product")
    category=fields.Many2one("product.category", string="Category")
    attribute=fields.Many2many("product.attribute", string="Attribute")
    threshold_value=fields.Integer(string="Threshold Value")
    transfer_quantity=fields.Integer(string="Transfer Quantity")
    status_button=fields.Selection([('0','Active'),('1','Dissmiss')], default='0', index=True, string="Status")
    threshold_selection=fields.Selection([('0','Product'),('1','Category'),], default= '0', index=True, string="Threshold Selection")

product_quantity=fields.Integer(compute="_product_based_on_warehouse", store=True)

@api.depends('main_location','product_quantity')
def _product_based_on_warehouse(self):
    count_products = 0 
self.env['product.template'].with_context(warehouse=self.main_location).search([], limit=1)
self.product_quantity=products print(f'Product Quantity: {self.product_quantity}')
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-27 08:32:29

您必须使用一个特殊的上下文值warehouse加载/浏览产品,以获得所有、一个或多个仓库的所有数量值。

代码语言:javascript
复制
# load all products and use a warehouse id
products = self.env['product.product'].with_context(warehouse=1).search([])
# load one product and use a warehouse name
products = self.env['product.product'].with_context(warehouse="Main Warehouse").search([], limit=1)
# load product with ID 1 and use a list of warehouse IDs
products = self.env['product.product'].with_context(warehouse=[1,2]).browse([1])

您可以使用产品的4个quantity字段来获取所需的数量值。还可以选择使用location作为上下文值,其方式与使用warehouse的方式相同。

如果您想知道这是从哪里来的,请查看_compute_quantities_compute_quantities_dict和最重要的方法_get_domain_locations

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55371796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档