如何在Pos odoo中加载qty_avaiable

问题描述

enter image description here

我只想加载仅在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}}。