【问题标题】:How to load qty_avaiable in Pos odoo如何在 Pos odoo 中加载 qty_avaiable
【发布时间】:2021-01-03 12:17:42
【问题描述】:

我只想加载仅在 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] 功能吗?

【问题讨论】:

    标签: javascript odoo pos


    【解决方案1】:

    我建议不要加载product.product 模型qty_available 字段,而是使用inventory_quantity 字段加载模型stock.quant。请记住,根据产品配置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 过滤,这是 POS 的选定库存位置,loaded 接收 data 结果,因此该库存位置的 stock.quant 记录,您可以遍历此记录并存储 @987654340 @使用this.db.product_by_id[record.product_id]. available_qty=record.inventory_quantity

    【讨论】:

    • 我明白你说的。但我不知道如何与product.product 映射。可以写示例代码吗?
    • 我所说的映射的意思是,在stock.quant 模型信息上,您将拥有product_id,您可以将该值与product.product 模型信息匹配。
    • 是的。我知道 stock.quant 有 product_id 但在 js 文件中,我不知道如何编写映射代码。@arryph
    • 那么您必须分享到目前为止您做了什么以及您面临的问题是什么。或者,如果您不熟悉所需的 JavaScript 知识,也许您可​​以使用这个免费的插件,如果它满足您的要求。 apps.odoo.com/apps/modules/13.0/bi_pos_stock
    猜你喜欢
    • 1970-01-01
    • 2020-08-06
    • 2020-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-11
    • 2018-12-21
    • 1970-01-01
    相关资源
    最近更新 更多