odoo.define("pos_product_hide_subcategory.db", function (require) {
    "use strict";

    var PosDB = require("point_of_sale.DB");
    var utils = require('web.utils');

    PosDB.include({
        add_products: function (products) {
            var stored_categories = this.product_by_category_id;

            if(!(products instanceof Array)){
                products = [products];
            }
            for(var i = 0, len = products.length; i < len; i++){
                var product = products[i];
                if (product.id in this.product_by_id) continue;
                if (product.available_in_pos){
                    var search_string = utils.unaccent(this._product_search_string(product));
                    var categ_id = product.pos_categ_id ? product.pos_categ_id[0] : this.root_category_id;
                    product.product_tmpl_id = product.product_tmpl_id[0];
                    if(!stored_categories[categ_id]){
                        stored_categories[categ_id] = [];
                    }
                    stored_categories[categ_id].push(product.id);
    
                    if(this.category_search_string[categ_id] === undefined){
                        this.category_search_string[categ_id] = '';
                    }
                    this.category_search_string[categ_id] += search_string;
                }
                this.product_by_id[product.id] = product;
                if(product.barcode && product.active){
                    this.product_by_barcode[product.barcode] = product;
                }
            }
        },
    });
});