function missing_product (widget) { "use strict"; var model = openerp; widget.MissingProductWidget = widget.Base.extend({ template: 'MissingProduct', stockQuant: [], productProduct: [], modelId: [], events: { 'click a': 'showCustomers', 'click h2': 'showCustomers', }, init: function (parent) { this._super(parent, { width: 3, height: 2 }); }, start: function () { var self = this; self.fetchInitial(); }, fetchInitial: function () { var self = this; self.$el.find('#morosidad').block({ message: null, overlayCSS: { backgroundColor: '#FAFAFA' } }); self.$el.find('.widget-content.widget-loading').css('display','flex'); // Iniciar Consultas self.fetchProductProduct().then(function(productProduct) { return productProduct; }).then(function(productProduct) { self.productProduct = productProduct; return self.fetchGetModelId(); }).then(function(modelId) { self.modelId = modelId; return self.fetchReduceProduct(); }); }, // getModelId fetchGetModelId: function() { var self = this; var defer = $.Deferred(); var irModelData = new model.web.Model('ir.model.data'); var getObtjectReference = irModelData.get_func('get_object_reference'); this.alive(getObtjectReference('product', 'product_normal_form_view')).then(function(results) { defer.resolve(results); }); return defer; }, fetchProductProduct : function(stockQaunt) { var self = this; var defer = $.Deferred(); var product_id = _.map(stockQaunt,function(map) { return map.product_id[0]; }); var fields = ['id', 'name_template', 'qty_available']; var domain = [['qty_available', '<=', 0],['type', '=', 'product'],['active','=',true]]; var productProduct = new model.web.Model('product.product'); productProduct.query(fields).filter(domain).all().then(function(results) { defer.resolve(results); }); return defer; }, // // Reduce Move line fetchReduceProduct: function () { var self = this; var cantidad; cantidad = _.countBy(_.map(self.productProduct,function(map) { return map.id; }),function(num) { return num ? 'even': 'odd'; }); if (!cantidad.even) { cantidad = {}; cantidad.even = 0; } self.$el.find('.widget-content.widget-loading').css('display','none'); self.$el.find('.widget-content').find('a').text(cantidad.even); self.$el.find('#morosidad').unblock(); }, showCustomers: function (e) { var self = this; if (self.productProduct.length === 0 ) { model.web.notification.do_warn("Atención","Sin datos"); return } this.do_action({ name: "Listado de productos faltan-tes", type: 'ir.actions.act_window', res_model: "product.product", views: [[false, 'list'],[self.modelId[1],'form']], target: 'current', domain: [['type', '=', 'product'],['qty_available','<=',0]], context: {}, }); } }); }