简体   繁体   中英

How to load qty_avaiable in Pos odoo

在此处输入图片说明 I want to load only quantity that exit in only pos's stock location.When I use qty_available, it load all quantity of product .How can I do that?

 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']);

How can replace my code for only qty_available for specific location.Can we use self.env['product.product] feature in js file?

I would suggest to instead of loading product.product model qty_available field, you load model stock.quant with inventory_quantity field. Keep in mind that based on product configuration Lot serial tracking, owner etc, for same product there can be multiple stock.quant . Total quantity would be the sum of those lines inventory_quantity value. You will have to use this.pos.config.location_id as domain to filter only quantity on the pos stock location. On load function you can map that information with product.product model data loaded.

// 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.
// }]

This is the load_models function documentation. domain have to be filtered by this.pos.config.location_id which is the selected Stock location for the POS, loaded receives the data result so stock.quant records for that stock location, you can loop through this records and store available_qty using this.db.product_by_id[record.product_id]. available_qty=record.inventory_quantity this.db.product_by_id[record.product_id]. available_qty=record.inventory_quantity .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM