Quellcode durchsuchen

[ADD] Ranking de serevicios

adrielso vor 7 Jahren
Ursprung
Commit
2e3c75d4ed

+ 2 - 1
static/src/js/widgets/monthly_purchases.js

@@ -168,7 +168,8 @@ function monthly_purchases(widget) {
         // modal
         // modal
         showCustomers: function (e) {
         showCustomers: function (e) {
             var self = this;
             var self = this;
-            if (self.accountVoucher.length === 0) {
+
+            if (self.accountInvoice.length === 0) {
                 model.web.notification.do_warn("Atención","Sin datos");
                 model.web.notification.do_warn("Atención","Sin datos");
                 return
                 return
             }
             }

+ 99 - 66
static/src/js/widgets/ranking_sales_product.js

@@ -5,19 +5,20 @@ function ranking_sales_product (widget) {
 
 
     widget.RankingSalesProductWidget = widget.Base.extend({
     widget.RankingSalesProductWidget = widget.Base.extend({
         template: 'RankingSalesProductTmpl',
         template: 'RankingSalesProductTmpl',
-        data : [],
-        accountInvoice : [],
-        invoiceLine : [],
-        productProduct : [],
-        ranking:[],
-        modelId:[],
+        data: [],
+        accountInvoice: [],
+        invoiceLine: [],
+        productProduct: [],
+        ranking: [],
+        modelId: [],
 
 
         events: {
         events: {
-            'click canvas': 'showCustomers'
+            // 'click canvas': 'showCustomers'
+            'click h2': 'showCustomers'
         },
         },
         init: function (parent) {
         init: function (parent) {
             this._super(parent, {
             this._super(parent, {
-                width : 6,
+                width: 6,
                 height: 4
                 height: 4
             });
             });
         },
         },
@@ -25,7 +26,7 @@ function ranking_sales_product (widget) {
             var self = this;
             var self = this;
             self.fetchInitial();
             self.fetchInitial();
         },
         },
-        fetchInitial:function(){
+        fetchInitial: function() {
             var self = this;
             var self = this;
             self.$el.block({
             self.$el.block({
                 message: null,
                 message: null,
@@ -34,6 +35,7 @@ function ranking_sales_product (widget) {
                 }
                 }
             });
             });
             self.$el.find('.widget-content.widget-loading').css('display','flex');
             self.$el.find('.widget-content.widget-loading').css('display','flex');
+
             self.fecthInvoice().then(function (accountInvoice) {
             self.fecthInvoice().then(function (accountInvoice) {
                 return accountInvoice;
                 return accountInvoice;
             }).then(function (accountInvoice) {
             }).then(function (accountInvoice) {
@@ -46,28 +48,28 @@ function ranking_sales_product (widget) {
                 self.productProduct = productProduct;
                 self.productProduct = productProduct;
                 return self.fetchGetModelId();
                 return self.fetchGetModelId();
             }).then(function(modelId){
             }).then(function(modelId){
-                self.modelId=modelId;
+                self.modelId = modelId;
                 return self.fetchProductRanking();
                 return self.fetchProductRanking();
             });
             });
         },
         },
         // getModelId
         // getModelId
-        fetchGetModelId: function(){
+        fetchGetModelId: function() {
             var self = this;
             var self = this;
             var defer = $.Deferred();
             var defer = $.Deferred();
             var irModelData = new model.web.Model('ir.model.data');
             var irModelData = new model.web.Model('ir.model.data');
             var getObtjectReference = irModelData.get_func('get_object_reference');
             var getObtjectReference = irModelData.get_func('get_object_reference');
 
 
-
-            this.alive(getObtjectReference('product', 'product_normal_form_view')).then(function(results){
+            this.alive(getObtjectReference('product', 'product_normal_form_view')).then(function(results) {
                 defer.resolve(results);
                 defer.resolve(results);
             });
             });
+
             return defer;
             return defer;
         },
         },
         // Obtener factura
         // Obtener factura
-        fecthInvoice: function(){
+        fecthInvoice: function() {
             var self = this;
             var self = this;
-            var desde =moment().format('YYYY-MM-01');
-            var hasta =moment().add(1,'months').format('YYYY-MM-01');
+            var desde = moment().format('YYYY-MM-01');
+            var hasta = moment().add(1,'months').format('YYYY-MM-01');
             var defer = $.Deferred();
             var defer = $.Deferred();
             var fields = ['id', 'invoice_line', 'date_invoice'];
             var fields = ['id', 'invoice_line', 'date_invoice'];
             var domain = [['type', '=', 'out_invoice'], ['date_invoice', '>=', desde], ['date_invoice', '<', hasta], ['state', 'in', ['open','paid']]];
             var domain = [['type', '=', 'out_invoice'], ['date_invoice', '>=', desde], ['date_invoice', '<', hasta], ['state', 'in', ['open','paid']]];
@@ -79,18 +81,19 @@ function ranking_sales_product (widget) {
             return defer;
             return defer;
         },
         },
         // Obtener linea de la factura
         // Obtener linea de la factura
-        fecthInvoiceLine: function(accountInvoice){
+        fecthInvoiceLine: function(accountInvoice) {
             var self = this;
             var self = this;
             var defer = $.Deferred();
             var defer = $.Deferred();
             var invoice_line = _.flatten(_.map(accountInvoice, function (item) {
             var invoice_line = _.flatten(_.map(accountInvoice, function (item) {
-                return item.invoice_line
+                return item.invoice_line;
             }));
             }));
-            var fields =['id', 'product_id', 'quantity'];
+            var fields = ['id', 'product_id', 'quantity'];
             var domain = [['id','in', invoice_line]];
             var domain = [['id','in', invoice_line]];
             var invoiceLine = new model.web.Model('account.invoice.line');
             var invoiceLine = new model.web.Model('account.invoice.line');
             invoiceLine.query(fields).filter(domain).all().then(function (results) {
             invoiceLine.query(fields).filter(domain).all().then(function (results) {
                 defer.resolve(results);
                 defer.resolve(results);
             });
             });
+
             return defer;
             return defer;
         },
         },
         // Obtener Prodcutos
         // Obtener Prodcutos
@@ -98,11 +101,11 @@ function ranking_sales_product (widget) {
             var self = this;
             var self = this;
             var defer = $.Deferred();
             var defer = $.Deferred();
             var product_id = _.flatten(_.map(invoiceLine,function (item) {
             var product_id = _.flatten(_.map(invoiceLine,function (item) {
-                return item.product_id[0]
+                return item.product_id[0];
             }));
             }));
             var fields = ['id', 'name_template', 'type'];
             var fields = ['id', 'name_template', 'type'];
-            var domain =[['id', 'in', product_id]];
-            var product= new model.web.Model('product.product');
+            var domain = [['id', 'in', product_id]];
+            var product = new model.web.Model('product.product');
 
 
             product.query(fields).filter(domain).all().then(function (results) {
             product.query(fields).filter(domain).all().then(function (results) {
                 defer.resolve(results);
                 defer.resolve(results);
@@ -110,7 +113,7 @@ function ranking_sales_product (widget) {
 
 
             return defer;
             return defer;
         },
         },
-        fetchProductRanking: function(){
+        fetchProductRanking: function() {
             var self = this;
             var self = this;
             var itemProduct;
             var itemProduct;
             var itemLine;
             var itemLine;
@@ -119,37 +122,43 @@ function ranking_sales_product (widget) {
             var lineUnik;
             var lineUnik;
             for (var i = 0; i < self.productProduct.length; i++) {
             for (var i = 0; i < self.productProduct.length; i++) {
                 itemProduct = self.productProduct[i];
                 itemProduct = self.productProduct[i];
-                itemLine= self.getInvoiceLine(itemProduct.id);
-
-                if (itemProduct.type == 'product'){
-                    if (itemLine.length > 0){
-                        cat = _.reduce(_.map(itemLine, function (map) {
-                            return map.quantity
-                        }), function (meno,num) {
-                            return meno + num
-                        }, 0);
-                        lineUnik = itemLine.shift();
-                        ranking.push({
-                                    product : itemProduct.name_template,
-                                    qty : cat,
-                                    id : lineUnik.product_id[0]
-                        });
-                    }
+                itemLine = self.getInvoiceLine(itemProduct.id);
+
+                // if (itemProduct.type === 'product') {
+                if (itemLine.length > 0) {
+                    cat = _.reduce(_.map(itemLine, function (map) {
+                        return map.quantity
+                    }), function (meno,num) {
+                        return meno + num
+                    }, 0);
+
+                    lineUnik = itemLine.shift();
+
+                    ranking.push({
+                        product: itemProduct.name_template,
+                        qty: cat,
+                        id: lineUnik.product_id[0],
+                        type: itemProduct.type
+                    });
                 }
                 }
+                // }
             }
             }
-            ranking.sort(function (a, b) {
+            ranking.sort(function(a, b) {
                 return b.qty - a.qty
                 return b.qty - a.qty
             });
             });
+
             self.$el.unblock();
             self.$el.unblock();
             self.$el.find('.widget-content.widget-loading').css('display','none');
             self.$el.find('.widget-content.widget-loading').css('display','none');
             var fecha = new Date();
             var fecha = new Date();
             var meses = new Array ("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
             var meses = new Array ("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
-            self.$el.find('.widget-title').find('span').text("Ranking de productos más vendidos del mes de " + meses[fecha.getMonth()]);
-            self.ranking=ranking;
+
+            self.$el.find('.widget-title').find('span').text("Ranking de productos y servicios del mes de " + meses[fecha.getMonth()]);
+            // self.$el.find('.widget-title').find('span').text("Ranking de productos más vendidos del mes de " + meses[fecha.getMonth()]);
+            self.ranking = ranking;
             self.fetchChart(ranking);
             self.fetchChart(ranking);
         },
         },
         // get line
         // get line
-        getInvoiceLine: function (product_id){
+        getInvoiceLine: function (product_id) {
             var self = this;
             var self = this;
             return _.flatten(_.filter(self.invoiceLine,function (line) {
             return _.flatten(_.filter(self.invoiceLine,function (line) {
                 return line.product_id[0] === product_id
                 return line.product_id[0] === product_id
@@ -159,59 +168,83 @@ function ranking_sales_product (widget) {
         fetchChart: function (ranking){
         fetchChart: function (ranking){
             var self = this;
             var self = this;
             var label = [];
             var label = [];
-            var body = [];
-            var item;
+            var bodyProducto = [];
+            var labelService = [];
+            var bodyService = [];
             var rank = 7;
             var rank = 7;
+            var item;
 
 
-            if (ranking.length < rank && ranking.length > 0)
-                rank= ranking.length;
+            // if (ranking.length < rank && ranking.length > 0)
+            //     rank= ranking.length;
 
 
             for (var i = 0; i < rank; i++) {
             for (var i = 0; i < rank; i++) {
                 if (ranking[i]){
                 if (ranking[i]){
                     item = ranking[i];
                     item = ranking[i];
-                }
-
-                if (ranking.length === 0){
+                }else{
                     item = {};
                     item = {};
                     item.product = "N/A";
                     item.product = "N/A";
                     item.qty = 0;
                     item.qty = 0;
                 }
                 }
-                var name=item.product.split(' ');
+                // if (ranking.length === 0){
+                    // item = {};
+                    // item.product = "N/A";
+                    // item.qty = 0;
+                // }
+                var name = item.product.split(' ');
 
 
                 if (name.length === 1) {
                 if (name.length === 1) {
                         label.push(name[0]);
                         label.push(name[0]);
                 }else{
                 }else{
                     label.push(name[0]+"("+name[name.length-1]+")");
                     label.push(name[0]+"("+name[name.length-1]+")");
                 }
                 }
-
-                body.push(item.qty);
+                if (item.type === 'product'){
+                    bodyService.push(0);
+                    bodyProducto.push(item.qty);
+                }
+                if (item.type === 'service'){
+                    bodyService.push(item.qty);
+                    bodyProducto.push(0);
+                }
             }
             }
+
             var chart = new Chart(this.$el.find(".widget-content").find('canvas'), {
             var chart = new Chart(this.$el.find(".widget-content").find('canvas'), {
-                // type: 'pie',
+                // type: 'line',
                 type: 'bar',
                 type: 'bar',
                 data: {
                 data: {
                     labels: label,
                     labels: label,
                     datasets: [
                     datasets: [
                         {
                         {
+                            label: 'Productos ',
+                             borderWidth: 1,
+                            backgroundColor: [  '#EF5350', '#EC407A', '#AB47BC', '#7E57C2', '#5C6BC0', '#42A5F5', '#26C6DA', '#26A69A', '#66BB6A', '#9CCC65'],
+                            data: bodyProducto,
+                        },
+                        {
+                            label: 'Servicios ',
+                             borderWidth: 1,
                             backgroundColor: [  '#EF5350', '#EC407A', '#AB47BC', '#7E57C2', '#5C6BC0', '#42A5F5', '#26C6DA', '#26A69A', '#66BB6A', '#9CCC65'],
                             backgroundColor: [  '#EF5350', '#EC407A', '#AB47BC', '#7E57C2', '#5C6BC0', '#42A5F5', '#26C6DA', '#26A69A', '#66BB6A', '#9CCC65'],
-                            data: body,
+                            data: bodyService,
                         }
                         }
                     ]
                     ]
                 },
                 },
                 options: {
                 options: {
-                   scales: {
-                       xAxes: [{ stacked: true }],
-                       yAxes: [{ stacked: true }],
+                    tooltips: {
+                       mode: 'index',
+                       intersect: true
                    },
                    },
                    legend: {
                    legend: {
-                       display: false,
+                       labels: {
+                           boxWidth: 10,
+                           fontSize: 12,
+                       },
+                       position: 'left',
                    },
                    },
                     layout: {
                     layout: {
-                        padding:{
+                        padding: {
                             top: 20,
                             top: 20,
-                            bottom:0,
-                            left : 0,
-                            rigth:0,
+                            bottom: 0,
+                            left: 0,
+                            rigth: 0,
                         }
                         }
                     },
                     },
                 }
                 }
@@ -224,9 +257,9 @@ function ranking_sales_product (widget) {
                 model.web.notification.do_warn("Atención","Sin datos");
                 model.web.notification.do_warn("Atención","Sin datos");
                 return
                 return
             }
             }
-            var hoy =moment().format('YYYY-MM-DD');
+            var hoy = moment().format('YYYY-MM-DD');
 
 
-            var product_id= _.map(self.ranking,function(map){
+            var product_id = _.map(self.ranking,function(map){
                 return map.id;
                 return map.id;
             })
             })
             this.do_action({
             this.do_action({
@@ -235,7 +268,7 @@ function ranking_sales_product (widget) {
                 res_model: "product.product",
                 res_model: "product.product",
                 views: [[false, 'list'],[self.modelId[1],'form']],
                 views: [[false, 'list'],[self.modelId[1],'form']],
                 target: 'current',
                 target: 'current',
-                domain: [['id', 'in', product_id],['type','=', 'product']],
+                domain: [['id', 'in', product_id]],
                 context: {},
                 context: {},
             });
             });
         }
         }

+ 2 - 1
static/src/xml/widgets/ranking_sales_product.xml

@@ -5,7 +5,8 @@
         <t t-call="WidgetBaseTmpl">
         <t t-call="WidgetBaseTmpl">
             <h2  class="widget-title">
             <h2  class="widget-title">
                 <i class="fa fa-bar-chart" aria-hidden="true"></i>
                 <i class="fa fa-bar-chart" aria-hidden="true"></i>
-                <span>Ranking de productos más vendidos</span>
+                <!-- <span>Ranking de productos más vendidos</span> -->
+                <span>Ranking de productos y servicios</span>
             </h2>
             </h2>
             <div class="widget-content">
             <div class="widget-content">
                 <canvas></canvas>
                 <canvas></canvas>