diff --git a/pos_product_template/static/src/js/ppt.js b/pos_product_template/static/src/js/ppt.js index bf90edc4..a11de48d 100644 --- a/pos_product_template/static/src/js/ppt.js +++ b/pos_product_template/static/src/js/ppt.js @@ -396,6 +396,15 @@ odoo.define("pos_product_template.pos_product_template", function(require){ this._super(options); }, + add_products: function(products){ + this._super(products); + // if pos_cache is also installed - then products are not available when product.templates are already loaded + // so we have to re add them here + if (this.raw_templates) { + this.add_templates(this.raw_templates); + } + }, + get_product_by_value_and_products: function(value_id, products){ var list = []; for (var i = 0, len = products.length; i < len; i++) { @@ -482,20 +491,9 @@ odoo.define("pos_product_template.pos_product_template", function(require){ - Load 'name' field of model product.product; - Load product.template model; *********************************************************** */ - // change product.product call - models.PosModel.prototype.models.some(function (model) { - if (model.model !== 'product.product') { - return false; - } - // add name and attribute_value_ids to list of fields - // to fetch for product.product - ['name', 'attribute_value_ids'].forEach(function (field) { - if (model.fields.indexOf(field) == -1) { - model.fields.push(field); - } - }); - return true; //exit early the iteration of this.models - }); + // change product.product fields - add name and attribute_value_ids + models.load_fields("product.product", ['name', 'attribute_value_ids']); + //Add our new models models.PosModel.prototype.models.push({ @@ -517,7 +515,11 @@ odoo.define("pos_product_template.pos_product_template", function(require){ display_default_code: false, };}, loaded: function(self, templates){ - self.db.add_templates(templates); + if (Object.keys(self.db.product_by_id).length > 0) { + self.db.add_templates(templates); + } else { + self.db.raw_templates = templates; + } }, }, { @@ -540,6 +542,7 @@ odoo.define("pos_product_template.pos_product_template", function(require){ self.db.add_product_attribute_values(values); }, }); + return { 'SelectVariantPopupWidget': SelectVariantPopupWidget, 'VariantListWidget': VariantListWidget,