问题描述
我只想加载仅在pos库存位置退出的数量。当我使用qty_available时,它将加载所有数量的产品。我该怎么做?
var ks_models = require('point_of_sale.models');
var ks_screens = require('point_of_sale.screens');
var ks_utils = require('ks_pos_low_stock_alert.utils');
ks_models.load_fields('product.product',['type','qty_available']);
如何仅在特定位置可用qty_available替换我的代码。我们可以在js文件中使用self.env ['product.product]功能吗?
解决方法
我建议您使用product.product
字段来加载模型qty_available
,而不是加载stock.quant
模型inventory_quantity
字段。请记住,根据产品配置Lot serial tracking,owner
等,同一产品可以有多个stock.quant
。总数量将是这些行inventory_quantity
值的总和。您将必须使用this.pos.config.location_id
作为域来仅过滤pos库存位置上的数量。在load
函数中,您可以将信息与已加载的product.product
模型数据进行映射。
// models: [{
// model: [string] the name of the openerp model to load.
// label: [string] The label displayed during load.
// fields: [[string]|function] the list of fields to be loaded.
// Empty Array / Null loads all fields.
// order: [[string]|function] the models will be ordered by
// the provided fields
// domain: [domain|function] the domain that determines what
// models need to be loaded. Null loads everything
// ids: [[id]|function] the id list of the models that must
// be loaded. Overrides domain.
// context: [Dict|function] the openerp context for the model read
// condition: [function] do not load the models if it evaluates to
// false.
// loaded: [function(self,model)] this function is called once the
// models have been loaded,with the data as second argument
// if the function returns a promise,the next model will
// wait until it resolves before loading.
// }]
这是load_models
函数文档。 domain
必须由this.pos.config.location_id
过滤,loaded
是POS的选定库存位置,data
收到stock.quant
结果,因此available_qty
记录了该库存位置,您可以遍历此记录并使用this.db.product_by_id[record.product_id]. available_qty=record.inventory_quantity
存储{{1}}。