1

I want to load only product that exit in pos's stock location.I try with following code.But display all product.How can I do it?I try this module https://apps.odoo.com/apps/modules/13.0/pos_product_available/.But that module display all product.I want to only load product and it's quantity that exit in stock's location.

class PosConfig(models.Model):
    _inherit = "pos.config"

    show_qtys = fields.Boolean(
        "Show Product Qtys", help="Show Product Qtys in POS", default=True
    )
    default_location_src_id = fields.Many2one(
        "stock.location", related="picking_type_id.default_location_src_id"
    )

And I add this code in js file.

var rpc = require("web.rpc");
    var models = require("point_of_sale.models");
    var field_utils = require("web.field_utils");

    models.load_fields("product.product", ["qty_available", "type"]);

    var PosModelSuper = models.PosModel.prototype;
    models.PosModel = models.PosModel.extend({
        get_product_model: function() {
            return _.find(this.models, function(model) {
                return model.model === "product.product";
            });
        },
        initialize: function(session, attributes) {
            // Compatibility with pos_cache module
            // preserve product.product model data for future request
            this.product_product_model = this.get_product_model(this.models);
            PosModelSuper.initialize.apply(this, arguments);
        },
        load_server_data: function() {
            // Compatibility with pos_cache module
            var self = this;

            var loaded = PosModelSuper.load_server_data.call(this);
            if (this.get_product_model(this.models)) {
                return loaded;
            }
            // If product.product model is not presented in this.models after super was called then pos_cache module installed
            return loaded.then(function() {
                return rpc
                    .query({
                        model: "product.product",
                        method: "search_read",
                        args: [],
                        fields: ["qty_available", "type"],
                        domain: self.product_product_model.domain,
                        context: _.extend(self.product_product_model.context, {
                            location: self.config.default_location_src_id[0],
                        }),
                    })
                    .then(function(products) {
                        self.add_product_qty(products);
                    });
            });
        },
Neural
  • 370
  • 1
  • 11

1 Answers1

0

I solved it! I replaced:

                    context: _.extend(self.product_product_model.context, {
                        location: self.config.default_location_src_id[0],
                    }),
                })

with:

                    context:{'location': self.config.default_location_src_id[0] },
                })
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83