Browse Source

Reportes varios de pack de productos

sebas 2 years ago
commit
a507f671fb

+ 3 - 0
__init__.py

@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+import controllers
+import models

BIN
__init__.pyc


+ 24 - 0
__openerp__.py

@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+{
+    'name': "Eiru Reports Pack de Productos",
+    'author': "Eiru",
+    'category': 'report',
+    'version': '0.1',
+    'depends': [
+        'base',
+        'point_of_sale',
+        'product_pack',
+        'account',
+        'eiru_assets',
+        'eiru_reports',
+    ],
+    'qweb': [
+        'static/src/xml/*.xml',
+        'static/src/reports/*.xml'
+    ],
+    'data': [
+        'templates.xml',
+        'views/actions.xml',
+        'views/menus.xml',
+    ],
+}

+ 2 - 0
controllers.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+from openerp import http

BIN
controllers.pyc


+ 1 - 0
models.py

@@ -0,0 +1 @@
+# -*- coding: utf-8 -*-

BIN
models.pyc


BIN
static/description/icon.png


+ 10 - 0
static/src/css/custom.css

@@ -0,0 +1,10 @@
+.openerp_webclient_container {
+    height: 100% !important;
+    height: calc(100% - 45px) !important;
+    overflow: auto !important;
+  }
+
+.hover:hover{
+  cursor: grab;
+  cursor: -webkit-grab;
+}

+ 43 - 0
static/src/js/main.js

@@ -0,0 +1,43 @@
+openerp.eiru_reports_pack= function (instance) {
+    "use strict";
+
+    var reporting = instance.eiru_reports_pack;
+
+    reporting_base(instance,reporting);
+
+    try {
+        report_product_pack(reporting);
+        report_product_pack_utilidad(reporting);
+        report_product_pack_pos(reporting);
+
+    } catch (e) {
+        // ignorar error
+    }
+
+
+    /*
+    ================================================================================
+        HISTORICO DE PRODUCCION
+    ================================================================================
+     */
+    instance.web.client_actions.add('eiru_reports_pack.product_pack_report_action', 'instance.eiru_reports_pack.ReportProductPackWidget');
+
+
+    /*
+    ================================================================================
+        ANALISIS DE PRODUCCION
+    ================================================================================
+     */
+    instance.web.client_actions.add('eiru_reports_pack.mrp_utilidad_report_action', 'instance.eiru_reports_pack.ReportProductPackUtilidadWidget');
+
+    /*
+    ================================================================================
+        ANALISIS DE DE VENTAS POS POR RECETA
+    ================================================================================
+     */
+    instance.web.client_actions.add('eiru_reports_pack.product_packpos_report_action', 'instance.eiru_reports_pack.ReportProductPackPosWidget');
+
+
+
+
+}

+ 22 - 0
static/src/js/reporting_base.js

@@ -0,0 +1,22 @@
+function reporting_base (instance, widget) {
+    "use strict";
+
+    widget.Base = instance.Widget.extend({
+
+        position: 0,
+
+        init: function (parent, position) {
+            this._super(parent);
+            this.position = position || this.position;
+        },
+        start: function () {
+            
+        },
+        getPosition: function () {
+            return this.position;
+        },
+        setPosition: function (position) {
+            this.position = position;
+        }
+    });
+}

+ 372 - 0
static/src/js/reports/report_product_pack.js

@@ -0,0 +1,372 @@
+function report_product_pack (reporting) {
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportProductPackWidget = reporting.Base.extend({
+        template: 'ReportProductPack',
+        data: [],
+        PosOrderLine: [],
+        PosOrder: [],
+        invoiceLine: [],
+        productProduct: [],
+        productPack: [],
+        productAtributo: [],
+        ranking: [],
+        content: [],
+        modelId: [],
+
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+            'click #X' : 'factSearch',
+            'click #A' : 'factSearch',
+            'click #B' : 'factSearch',
+            'click #C' : 'factSearch',
+            'click #D' : 'factSearch',
+            'click #Z' : 'factSearch',
+
+            'click #Y' : 'factSearch',
+            'click-row.bs.table #table ' : 'clickAnalysisDetail',
+        },
+
+        init : function(parent){
+            this._super(parent);
+        },
+
+        start: function () {
+            var self = this;
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.rowsData});
+            this.submitForm();
+        },
+
+        // Redirecionar
+        renderReport: function () {
+            var self = this;
+
+            var container = this.$el.closest('.oe_form_sheet.oe_form_sheet_width');
+            this.$el.closest('.report_view').remove();
+            container.find('.report_view').show({
+                effect: 'fade',
+                duration: 200,
+            });
+        },
+        // Verificar el modelo
+        checkModel : function(model){
+            var self = this;
+            return _.filter(self.modules,function(item){return item.name === model});
+        },
+
+        // Lanzar el mensaje
+        showMensaje : function(modelos){
+            var self = this;
+            $("#dialog" ).dialog({
+                autoOpen: true,
+                resizable: false,
+                modal: true,
+                title: 'Atención',
+                width: 500,
+                open: function() {
+                    $(this).html('Reporte in-disponible, contacte con el administrador del sistema ref : '+modelos);
+                },
+                show: {
+                    effect: "fade",
+                    duration: 200
+                },
+                hide: {
+                    effect: "fade",
+                    duration: 200
+                },
+                buttons: {
+                    Aceptar: function() {
+                        $(this).dialog('close');
+                        self.renderReport()
+                    }
+                }
+            });
+            return
+        },
+
+        // Analisis Detallado
+        clickAnalysisDetail: function(e, row, $element, field){
+
+            if (field == 'product_main'){
+                this.do_action({
+                    name : "Registro de Producto",
+                    type : 'ir.actions.act_window',
+                    res_model : "product.product",
+                    views : [[false,'form']],
+                    target : 'new',
+                    domain : [['id','=', row.product_main_id]],
+                    context : {},
+                    flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id : row.product_main_id,
+                });
+            }
+
+            e.stopImmediatePropagation();
+        },
+
+        submitForm: function () {
+            var self = this;
+            self.fecthIrModuleModule().then(function(modules){
+                self.modules = modules;
+                return modules;
+            }).then(function(modules){
+                return self.fecthProductProduct();
+            }).then(function(productProduct){
+                self.productProduct = productProduct;
+                return self.fetchProductPack();
+            }).then(function(productPack){
+                self.productPack = productPack;
+                self.search();
+                return self.BuildTable();
+            });
+        },
+
+        // Modelos instalados
+        fecthIrModuleModule: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var fields = ['name','id'];
+            var domain=[['state','=','installed']];
+            var irModule = new instance.web.Model('ir.module.module');
+            irModule.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        // Obtener Productos
+        fecthProductProduct: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var modules = self.checkModel('product_pack');
+
+            if (modules.length <= 0){
+                self.showMensaje('product_pack');
+                return defer;
+            }
+
+            var fields = ['id', 'name','name_template', 'pack_line_ids','type', 'ean13','attribute_str'];
+            var domain = [['active', '=', true],['pack', '=', true]];
+            var ProductProduct = new instance.web.Model('product.product');
+            ProductProduct.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+
+        // Product Pack
+        fetchProductPack: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var ids = _.flatten(_.map(self.productProduct,function (item) {
+                return item.id;
+            }));
+            var fields = ['id','product_id', 'price','parent_product_id', 'quantity', 'subtotal'];
+            var domain = [['parent_product_id', 'in', ids]];
+            var ProductPack =  new instance.web.Model('product.pack.line');
+            ProductPack.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        getProductPack: function(id){
+            var self = this;
+            return _.filter(self.productPack,function (item) {
+                return item.parent_product_id[0] == id;
+            });
+        },
+
+        search: function () {
+            var self = this;
+            var results = self.productProduct;
+            results = _.map(results, function (item) {
+                return {
+                        label: item.id + '- '+ ' [ ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) ' ,
+                        value: item.id + '- '+ ' [ ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) '
+                }
+            });
+            self.$('#product').autocomplete({
+                source: results,
+                minLength:0,
+                search: function(event, ui) {
+                    if (!(self.$('#product').val())){
+                        self.factSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.factSearch();
+                },
+                select: function(event, ui) {
+                    self.factSearch();
+                }
+            });
+        },
+
+        // Generar el ranking
+        BuildTable: function() {
+            var self = this;
+            var ProductProduct = self.productProduct;
+            var itemProduct;
+            var itemLine;
+            var itemProductPack;
+            var itemPack;
+            var qty = 0;
+            var rankingItem = [];
+            var rankingCab = [];
+            var cat = 0;
+            var countPack = 0;
+            var attribute;
+
+            _.each(ProductProduct, function(item){
+
+                if(item.attribute_str){
+                    attribute = ' ' + item.attribute_str;
+                }else{
+                    attribute = ' ';
+                }
+                itemProductPack = self.getProductPack(item.id);
+
+                rankingItem.push({
+                    product_main: item.name_template + attribute,
+                    product: "",
+                    qty: "",
+                    countPack: "",
+                    product_main_id: item.id
+                });
+
+                for (var i = 0; i < itemProductPack.length; i++) {
+
+
+                    if (itemProductPack.length > 0){
+                        rankingItem.push({
+                            product_main: "",
+                            product: itemProductPack[i].product_id[1],
+                            qty: accounting.formatNumber(itemProductPack[i].quantity,3,".",","),
+                            countPack: itemProductPack[i].quantity,
+                            product_main_id: itemProductPack[i].parent_product_id[0],
+                        })
+                    }
+                }
+
+
+                // Generar Objeto Principal
+                rankingItem=rankingItem.concat(rankingCab);
+
+            });
+
+            self.content = rankingItem;
+            self.loadTable(rankingItem);
+
+        },
+
+        factSearch: function(){
+            var self = this;
+            var product = this.$el.find('#product').val().split('-');
+
+            var content = self.content;
+
+
+            if (product != ""){
+                content = _.filter(content, function(inv){
+                    return inv.product_main_id == product[0];
+                    //return inv.product_main_id == product;
+                });
+            }
+
+            self.loadTable(content)
+        },
+
+        loadTable:function(rowsTable){
+            var self = this;
+            self.rowsData = rowsTable;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load',rowsTable);
+        },
+
+        getObjetPdf: function(rowsTable){
+            var self = this;
+            var rows=self.rowsData;
+
+            return rows;
+        },
+
+        clickOnAction: function (e) {
+            var self = this;
+            var rowsNew;
+            var action = self.$el.find(e.target).val();
+            var table = self.$el.find("#table");
+            var data2 = table.bootstrapTable('getVisibleColumns');
+            var getColumns=[];
+            var rows=[];
+            rowsNew = self.getObjetPdf();
+            if (action === 'pdf') {
+                var dataNEW = _.map(data2, function (val){
+                    return val.field;
+                });
+                _.each(rowsNew,function (item){
+                    rows.push(_.pick(item, dataNEW));
+                });
+                // Obtener los nombre de la Cabezera
+                _.each(_.map(data2,function(val){
+                        return val;
+                    }), function(item){
+                            getColumns.push([{
+                                        title: item.title,
+                                        dataKey: item.field
+                                    }]);
+                });
+                this.drawPDF(_.flatten(getColumns),rows);
+            }
+        },
+        drawPDF: function (getColumns,rows) {
+            var self = this;
+            var fechaActu= new Date();
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new window.jsPDF();
+
+            pdfDoc.autoTable(getColumns, rows, {
+                styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
+                columnStyles: {
+                    product_main : {columnWidth: '6px'},
+                    product : {columnWidth: '8px'},
+                    qty : {halign:'right',columnWidth: '6px'},
+                },
+                margin: { top: 16, horizontal: 7},
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Listado de Receta de Pack de Producto ', data.settings.margin.left, 10);
+                    // FOOTER
+                    var str = "Pagina  " + data.pageCount;
+                    // Total page number plugin only available in jspdf v1.0+
+                    if (typeof pdfDoc.putTotalPages === 'function') {
+                        str = str + " de " + totalPagesExp;
+                    }
+                    pdfDoc.setFontSize(9);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text(str, data.settings.margin.left, pdfDoc.internal.pageSize.height - 5);
+                    }
+            });
+
+            if (typeof pdfDoc.putTotalPages === 'function') {
+                pdfDoc.putTotalPages(totalPagesExp);
+            }
+            pdfDoc.save('Listado de Receta de Pack de Producto.pdf')
+        },
+    });
+}

+ 532 - 0
static/src/js/reports/report_product_pack_pos.js

@@ -0,0 +1,532 @@
+function report_product_pack_pos (reporting) {
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportProductPackPosWidget = reporting.Base.extend({
+        template: 'ReportProductPackPos',
+        data: [],
+        PosOrderLine: [],
+        PosOrder: [],
+        ProductProduct: [],
+        rowsData: [],
+        productPack: [],
+        productAtributo: [],
+        ranking: [],
+        content: [],
+        modelId: [],
+
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+            'click #X' : 'factSearch',
+            'click #A' : 'factSearch',
+            'click #B' : 'factSearch',
+            'click #C' : 'factSearch',
+            'click #D' : 'factSearch',
+            'click #Z' : 'factSearch',
+            'change #from' : 'factSearch',
+            'change #to': 'factSearch',
+
+            'click #Y' : 'factSearch',
+            'click-row.bs.table #table ' : 'clickAnalysisDetail',
+        },
+
+        init : function(parent){
+            this._super(parent);
+        },
+
+        start: function () {
+            var self = this;
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.rowsData});
+            this.fecthFecha();
+            this.submitForm();
+        },
+
+        // Redirecionar
+        renderReport: function () {
+            var self = this;
+
+            var container = this.$el.closest('.oe_form_sheet.oe_form_sheet_width');
+            this.$el.closest('.report_view').remove();
+            container.find('.report_view').show({
+                effect: 'fade',
+                duration: 200,
+            });
+        },
+        // Verificar el modelo
+        checkModel : function(model){
+            var self = this;
+            return _.filter(self.modules,function(item){return item.name === model});
+        },
+
+        // Lanzar el mensaje
+        showMensaje : function(modelos){
+            var self = this;
+            $("#dialog" ).dialog({
+                autoOpen: true,
+                resizable: false,
+                modal: true,
+                title: 'Atención',
+                width: 500,
+                open: function() {
+                    $(this).html('Reporte in-disponible, contacte con el administrador del sistema ref : '+modelos);
+                },
+                show: {
+                    effect: "fade",
+                    duration: 200
+                },
+                hide: {
+                    effect: "fade",
+                    duration: 200
+                },
+                buttons: {
+                    Aceptar: function() {
+                        $(this).dialog('close');
+                        self.renderReport()
+                    }
+                }
+            });
+            return
+        },
+
+        // Analisis Detallado
+        clickAnalysisDetail: function(e, row, $element, field){
+
+            if (field == 'product_main'){
+                this.do_action({
+                    name : "Registro de Producto",
+                    type : 'ir.actions.act_window',
+                    res_model : "product.product",
+                    views : [[false,'form']],
+                    target : 'new',
+                    domain : [['id','=', row.product_main_id]],
+                    context : {},
+                    flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id : row.product_main_id,
+                });
+            }
+
+            e.stopImmediatePropagation();
+        },
+
+        fecthFecha: function() {
+            var to;
+            var dateFormat1 = "mm/dd/yy",
+                from = $( "#from" )
+                .datepicker({
+                  dateFormat: "dd/mm/yy",
+                  changeMonth: true,
+                  numberOfMonths: 1,
+                })
+                .on( "change", function() {
+                  to.datepicker( "option", "minDate", getDate(this), "dd/mm/yyyy");
+                });
+                to = $( "#to" ).datepicker({
+                dateFormat: "dd/mm/yy",
+                defaultDate: "+7d",
+                changeMonth: true,
+                numberOfMonths: 1,
+                })
+                .on( "change", function() {
+                    from.datepicker( "option", "maxDate", getDate(this));
+                });
+            function getDate( element ) {
+                var fechaSel =element.value.split('/');
+                var date;
+                try {
+                    date = $.datepicker.parseDate( dateFormat1, (fechaSel[1]+"/"+fechaSel[0]+"/"+fechaSel[2]));
+                } catch( error ) {
+                    date = null;
+                }
+                return date;
+            }
+        },
+
+        submitForm: function () {
+            var self = this;
+            self.fecthIrModuleModule().then(function(modules){
+                self.modules = modules;
+                return modules;
+            }).then(function(modules){
+                return self.fecthPosOrder();
+            }).then(function (PosOrder) {
+                self.PosOrder = PosOrder;
+                return self.fecthPosOrderLine(PosOrder);
+            }).then(function (PosOrderLine) {
+                self.PosOrderLine = PosOrderLine;
+                return self.fetchProductProduct();
+            }).then(function (ProductProduct) {
+                self.ProductProduct = ProductProduct;
+                return self.fetchProductPack();
+            }).then(function(productPack){
+                self.productPack = productPack;
+                self.search();
+                return self.BuildTable();
+            });
+        },
+
+        // Modelos instalados
+        fecthIrModuleModule: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var fields = ['name','id'];
+            var domain=[['state','=','installed']];
+            var irModule = new instance.web.Model('ir.module.module');
+            irModule.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        // Obtener Pedido ,['id', 'in', ['1065','1067']]
+        fecthPosOrder: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var modules = self.checkModel('point_of_sale');
+
+            if (modules.length <= 0){
+                self.showMensaje('point_of_sale');
+                return defer;
+            }
+
+            var fields = ['id', 'lines', 'date_order'];
+            var domain = [ ['state', 'in', ['paid','done','invoiced']]];
+            var PosOrder = new instance.web.Model('pos.order');
+            PosOrder.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+        // Obtener linea de la factura
+        fecthPosOrderLine: function(PosOrder) {
+            var self = this;
+            var defer = $.Deferred();
+            var lines = _.flatten(_.map(PosOrder, function (item) {
+                return item.lines;
+            }));
+            var fields = ['id', 'product_id', 'create_date', 'qty'];
+            var domain = [['id','in', lines]];
+            var PosOrderLine = new instance.web.Model('pos.order.line');
+            PosOrderLine.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+        // Obtener Productos ,['id', '=', 110]
+        fetchProductProduct: function (PosOrderLine) {
+            var self = this;
+
+            var defer = $.Deferred();
+            var modules = self.checkModel('product_pack');
+
+            if (modules.length <= 0){
+                self.showMensaje('product_pack');
+                return defer;
+            }
+            var product_id = _.flatten(_.map(PosOrderLine,function (item) {
+                return item.product_id[0];
+            }));
+            var fields = ['id', 'name','name_template', 'pack_line_ids','type', 'ean13','attribute_str', 'standard_price', 'lst_price'];
+            var domain = [['active', '=', true],['pack', '=', true]];
+            var ProductProduct = new instance.web.Model('product.product');
+            ProductProduct.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+
+        // Product Pack
+        fetchProductPack: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var ids = _.flatten(_.map(self.ProductProduct,function (item) {
+                return item.id;
+            }));
+            var fields = ['id','product_id', 'price','parent_product_id', 'quantity', 'subtotal'];
+            var domain = [['parent_product_id', 'in', ids]];
+            var ProductPack =  new instance.web.Model('product.pack.line');
+            ProductPack.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        getProductPack: function(id){
+            var self = this;
+            return _.filter(self.productPack,function (item) {
+                return item.parent_product_id[0] == id;
+            });
+        },
+
+        getPosOrder: function(id){
+            var self = this;
+            return _.filter(self.PosOrder,function (item) {
+                return item.id == id;
+            });
+        },
+
+        getProductProduct: function(id){
+            var self = this;
+            return _.filter(self.ProductProduct,function (item) {
+                return item.id == id;
+            });
+        },
+
+
+
+        // Obtener facturas por cada clientes
+        getPosOrderLiners:function(product_id) {
+            var self = this;
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+            var PosOrderLine = self.PosOrderLine;
+            // Hoy
+            if ($('#A').is(":checked")){
+                PosOrderLine = _.filter(PosOrderLine, function (inv){
+                    return moment(inv.create_date).format('YYYY-MM-DD') == moment().format('YYYY-MM-DD');
+                });
+            }
+            // Ayer
+            if ($('#B').is(":checked")){
+                PosOrderLine = _.filter(PosOrderLine, function (inv){
+                    return moment(inv.create_date).format('YYYY-MM-DD') == moment().add(-1,'days').format('YYYY-MM-DD');
+                });
+            }
+            // Mes Actual
+            if ($('#C').is(":checked")){
+                PosOrderLine = _.filter(PosOrderLine, function (inv){
+                    return moment(inv.create_date).format('MM') == moment().format('MM');
+                });
+            }
+            // Mes Pasado
+            if ($('#D').is(":checked")){
+                PosOrderLine = _.filter(PosOrderLine, function (inv){
+                    return moment(inv.create_date).format('MM') == moment().add(-1,'months').format('MM');
+                });
+            }
+            // Rango de fechas
+            if ($('#Z').is(":checked")){
+                $('#datepicker').css('display','block');
+                if (desde.length > 0){
+                    var date = desde.split('/');
+                    PosOrderLine = _.filter(PosOrderLine, function (inv){
+                        return moment(inv.create_date).format('YYYY-MM-DD') >= (date[2]+"-"+date[1]+"-"+date[0]);
+                    });
+                }
+                if (hasta.length > 0){
+                    var date= hasta.split('/');
+                    PosOrderLine = _.filter(PosOrderLine, function (inv){
+                        return moment(inv.create_date).format('YYYY-MM-DD') <= (date[2]+"-"+date[1]+"-"+date[0]);
+                    });
+                }
+            }else{
+                $('#datepicker').css('display','none');
+            }
+
+            return _.flatten(_.filter(PosOrderLine,function (inv) {
+                return inv.product_id[0] === product_id;
+            }));
+        },
+
+
+        // Generar el ranking
+        BuildTable: function() {
+            var self = this;
+            var itemProduct;
+            var itemLine;
+            var qty = 0;
+            var ProductProduct = self.ProductProduct;
+            var rankingCab = [];
+            var rankingItem = [];
+            var cat = 0;
+            var itemProductPack;
+            var countSalesOrder = 0;
+            var attribute;
+            var lineUnik;
+
+        _.each(ProductProduct, function(item){
+
+            itemLine = self.getPosOrderLiners(item.id);
+                          if (itemLine.length > 0) {
+                              cat = _.reduce(_.map(itemLine, function (map) {
+                                  return map.qty
+                              }), function (meno,num) {
+                                  return meno + num
+                              }, 0);
+                          }
+            if(item.attribute_str){
+                attribute = ' ' + item.attribute_str;
+            }else{
+                attribute = ' ';
+            }
+            itemProductPack = self.getProductPack(item.id);
+
+                          rankingItem.push({
+                              product_main: item.name_template+ attribute,
+                              product: "",
+                              qty_pos: cat,
+                              qty: "",
+                              countPack: "",
+                              product_main_id: item.id
+                          });
+
+            for (var i = 0; i < itemProductPack.length; i++) {
+
+
+                if (itemProductPack.length > 0){
+                                    rankingItem.push({
+                                        product_main: "",
+                                        product: itemProductPack[i].product_id[1],
+                                        qty_pos: cat,
+                                        qty: accounting.formatNumber((itemProductPack[i].quantity*cat),3,".",","),
+                                        countPack: itemProductPack[i].quantity*cat,
+                                        product_main_id: itemProductPack[i].parent_product_id[0],
+                                    })
+                }
+            }
+
+
+            // Generar Objeto Principal
+            rankingItem=rankingItem.concat(rankingCab);
+
+        });
+
+        self.content = rankingItem;
+        self.loadTable(rankingItem);
+
+     },
+
+        search: function () {
+            var self = this;
+            var results = self.ProductProduct;
+            results = _.map(results, function (item) {
+                return {
+                        label: item.id + '- '+ ' [ ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) ' ,
+                        value: item.id + '- '+ ' [ ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) '
+                }
+            });
+            self.$('#product').autocomplete({
+                source: results,
+                minLength:0,
+                search: function(event, ui) {
+                    if (!(self.$('#product').val())){
+                        self.factSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.factSearch();
+                },
+                select: function(event, ui) {
+                    self.factSearch();
+                }
+            });
+        },
+
+        factSearch: function(){
+            var self = this;
+            var product = this.$el.find('#product').val().split('-');
+            var content = self.content;
+
+            if (product != ""){
+                content = _.filter(content, function(inv){
+                    return inv.product_main_id == product[0];
+                });
+            }
+            // self.BuildTable();
+            self.loadTable(content)
+        },
+
+        loadTable:function(rowsTable){
+            var self = this;
+            self.rowsData = rowsTable;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load',rowsTable);
+        },
+
+        getObjetPdf: function(rowsTable){
+            var self = this;
+            var rows=self.rowsData;
+
+            return rows;
+        },
+
+        clickOnAction: function (e) {
+            var self = this;
+            var rowsNew;
+            var action = self.$el.find(e.target).val();
+            var table = self.$el.find("#table");
+            var data2 = table.bootstrapTable('getVisibleColumns');
+            var getColumns=[];
+            var rows=[];
+            rowsNew = self.getObjetPdf();
+            if (action === 'pdf') {
+                var dataNEW = _.map(data2, function (val){
+                    return val.field;
+                });
+                _.each(rowsNew,function (item){
+                    rows.push(_.pick(item, dataNEW));
+                });
+                // Obtener los nombre de la Cabezera
+                _.each(_.map(data2,function(val){
+                        return val;
+                    }), function(item){
+                            getColumns.push([{
+                                        title: item.title,
+                                        dataKey: item.field
+                                    }]);
+                });
+                this.drawPDF(_.flatten(getColumns),rows);
+            }
+        },
+        drawPDF: function (getColumns,rows) {
+            var self = this;
+            var fechaActu= new Date();
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new window.jsPDF();
+
+            pdfDoc.autoTable(getColumns, rows, {
+                styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
+                columnStyles: {
+                    product_main : {columnWidth: '7px'},
+                    product : {columnWidth: '9px'},
+                    qty_pos : {halign:'right',columnWidth: '5px'},
+                    qty : {halign:'right',columnWidth: '5px'},
+                },
+                margin: { top: 16, horizontal: 7},
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Análisis de ventas POS por insumos ', data.settings.margin.left, 10);
+                    // FOOTER
+                    var str = "Pagina  " + data.pageCount;
+                    // Total page number plugin only available in jspdf v1.0+
+                    if (typeof pdfDoc.putTotalPages === 'function') {
+                        str = str + " de " + totalPagesExp;
+                    }
+                    pdfDoc.setFontSize(9);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text(str, data.settings.margin.left, pdfDoc.internal.pageSize.height - 5);
+                    }
+            });
+
+            if (typeof pdfDoc.putTotalPages === 'function') {
+                pdfDoc.putTotalPages(totalPagesExp);
+            }
+            pdfDoc.save('Análisis de ventas POS por insumos.pdf')
+        },
+    });
+}

+ 621 - 0
static/src/js/reports/report_product_pack_utilidad.js

@@ -0,0 +1,621 @@
+function report_product_pack_utilidad (reporting) {
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportProductPackUtilidadWidget = reporting.Base.extend({
+        template: 'ReportProductPackUtilidad',
+        data: [],
+        PosOrderLine: [],
+        PosOrder: [],
+        invoiceLine: [],
+        ProductProduct: [],
+        rowsData: [],
+        productPack: [],
+        productAtributo: [],
+        ranking: [],
+        content: [],
+        modelId: [],
+
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+            'click #X' : 'factSearch',
+            'click #A' : 'factSearch',
+            'click #B' : 'factSearch',
+            'click #C' : 'factSearch',
+            'click #D' : 'factSearch',
+            'click #Z' : 'factSearch',
+            'change #from' : 'factSearch',
+            'change #to': 'factSearch',
+
+            'click #Y' : 'factSearch',
+            'click-row.bs.table #table ' : 'clickAnalysisDetail',
+        },
+
+        init : function(parent){
+            this._super(parent);
+        },
+
+        start: function () {
+            var self = this;
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.rowsData});
+            this.fecthFecha();
+            this.submitForm();
+        },
+
+        // Redirecionar
+        renderReport: function () {
+            var self = this;
+
+            var container = this.$el.closest('.oe_form_sheet.oe_form_sheet_width');
+            this.$el.closest('.report_view').remove();
+            container.find('.report_view').show({
+                effect: 'fade',
+                duration: 200,
+            });
+        },
+        // Verificar el modelo
+        checkModel : function(model){
+            var self = this;
+            return _.filter(self.modules,function(item){return item.name === model});
+        },
+
+        // Lanzar el mensaje
+        showMensaje : function(modelos){
+            var self = this;
+            $("#dialog" ).dialog({
+                autoOpen: true,
+                resizable: false,
+                modal: true,
+                title: 'Atención',
+                width: 500,
+                open: function() {
+                    $(this).html('Reporte in-disponible, contacte con el administrador del sistema ref : '+modelos);
+                },
+                show: {
+                    effect: "fade",
+                    duration: 200
+                },
+                hide: {
+                    effect: "fade",
+                    duration: 200
+                },
+                buttons: {
+                    Aceptar: function() {
+                        $(this).dialog('close');
+                        self.renderReport()
+                    }
+                }
+            });
+            return
+        },
+
+        // Analisis Detallado
+        clickAnalysisDetail: function(e, row, $element, field){
+
+            if (field == 'product_main'){
+                this.do_action({
+                    name : "Registro de Producto",
+                    type : 'ir.actions.act_window',
+                    res_model : "product.product",
+                    views : [[false,'form']],
+                    target : 'new',
+                    domain : [['id','=', row.product_main_id]],
+                    context : {},
+                    flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id : row.product_main_id,
+                });
+            }
+
+            e.stopImmediatePropagation();
+        },
+
+        fecthFecha: function() {
+            var to;
+            var dateFormat1 = "mm/dd/yy",
+                from = $( "#from" )
+                .datepicker({
+                  dateFormat: "dd/mm/yy",
+                  changeMonth: true,
+                  numberOfMonths: 1,
+                })
+                .on( "change", function() {
+                  to.datepicker( "option", "minDate", getDate(this), "dd/mm/yyyy");
+                });
+                to = $( "#to" ).datepicker({
+                dateFormat: "dd/mm/yy",
+                defaultDate: "+7d",
+                changeMonth: true,
+                numberOfMonths: 1,
+                })
+                .on( "change", function() {
+                    from.datepicker( "option", "maxDate", getDate(this));
+                });
+            function getDate( element ) {
+                var fechaSel =element.value.split('/');
+                var date;
+                try {
+                    date = $.datepicker.parseDate( dateFormat1, (fechaSel[1]+"/"+fechaSel[0]+"/"+fechaSel[2]));
+                } catch( error ) {
+                    date = null;
+                }
+                return date;
+            }
+        },
+
+        submitForm: function () {
+            var self = this;
+            self.fecthIrModuleModule().then(function(modules){
+                self.modules = modules;
+                return modules;
+            }).then(function(modules){
+                return self.fecthPosOrder();
+            }).then(function (PosOrder) {
+                self.PosOrder = PosOrder;
+                return self.fecthPosOrderLine(PosOrder);
+            }).then(function (PosOrderLine) {
+                self.PosOrderLine = PosOrderLine;
+                return self.fetchProductProduct();
+            }).then(function (ProductProduct) {
+                self.ProductProduct = ProductProduct;
+                return self.fetchProductPack();
+            }).then(function(productPack){
+                self.productPack = productPack;
+                self.search();
+                return self.BuildTable();
+            });
+        },
+
+        // Modelos instalados
+        fecthIrModuleModule: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var fields = ['name','id'];
+            var domain=[['state','=','installed']];
+            var irModule = new instance.web.Model('ir.module.module');
+            irModule.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        // Obtener Pedido ,['id', 'in', ['1065','1067']]
+        fecthPosOrder: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var modules = self.checkModel('point_of_sale');
+
+            if (modules.length <= 0){
+                self.showMensaje('point_of_sale');
+                return defer;
+            }
+
+            var fields = ['id', 'lines', 'date_order'];
+            var domain = [ ['state', 'in', ['paid','done','invoiced']]];
+            var PosOrder = new instance.web.Model('pos.order');
+            PosOrder.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+        // Obtener linea de la factura
+        fecthPosOrderLine: function(PosOrder) {
+            var self = this;
+            var defer = $.Deferred();
+            var lines = _.flatten(_.map(PosOrder, function (item) {
+                return item.lines;
+            }));
+            var fields = ['id', 'product_id', 'create_date', 'qty'];
+            var domain = [['id','in', lines]];
+            var PosOrderLine = new instance.web.Model('pos.order.line');
+            PosOrderLine.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+        // Obtener Productos ,['id', '=', 110]
+        fetchProductProduct: function (PosOrderLine) {
+            var self = this;
+
+            var defer = $.Deferred();
+            var modules = self.checkModel('product_pack');
+
+            if (modules.length <= 0){
+                self.showMensaje('product_pack');
+                return defer;
+            }
+            var product_id = _.flatten(_.map(PosOrderLine,function (item) {
+                return item.product_id[0];
+            }));
+            var fields = ['id', 'name','name_template', 'pack_line_ids','type', 'ean13','attribute_str', 'standard_price', 'lst_price'];
+            var domain = [['active', '=', true],['pack', '=', true]];
+            var ProductProduct = new instance.web.Model('product.product');
+            ProductProduct.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+
+        // Product Pack
+        fetchProductPack: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var ids = _.flatten(_.map(self.ProductProduct,function (item) {
+                return item.id;
+            }));
+            var fields = ['id','product_id', 'price','parent_product_id', 'quantity', 'subtotal'];
+            var domain = [['parent_product_id', 'in', ids]];
+            var ProductPack =  new instance.web.Model('product.pack.line');
+            ProductPack.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        getProductPack: function(id){
+            var self = this;
+            return _.filter(self.productPack,function (item) {
+                return item.parent_product_id[0] == id;
+            });
+        },
+
+        getPosOrder: function(id){
+            var self = this;
+            return _.filter(self.PosOrder,function (item) {
+                return item.id == id;
+            });
+        },
+
+        getProductProduct: function(id){
+            var self = this;
+            return _.filter(self.ProductProduct,function (item) {
+                return item.id == id;
+            });
+        },
+
+        search: function () {
+            var self = this;
+            var results = self.ProductProduct;
+            results = _.map(results, function (item) {
+                return {
+                        label: item.id + '- '+ ' [ ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) ' ,
+                        value: item.id + '- '+ ' [ ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) '
+                }
+            });
+            self.$('#product').autocomplete({
+                source: results,
+                minLength:0,
+                search: function(event, ui) {
+                    if (!(self.$('#product').val())){
+                        self.factSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.factSearch();
+                },
+                select: function(event, ui) {
+                    self.factSearch();
+                }
+            });
+        },
+
+        // Obtener facturas por cada clientes
+        getPosOrderLiners:function(product_id) {
+            var self = this;
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+            var PosOrderLine = self.PosOrderLine;
+            // Hoy
+            if ($('#A').is(":checked")){
+                PosOrderLine = _.filter(PosOrderLine, function (inv){
+                    return moment(inv.create_date).format('YYYY-MM-DD') == moment().format('YYYY-MM-DD');
+                });
+            }
+            // Ayer
+            if ($('#B').is(":checked")){
+                PosOrderLine = _.filter(PosOrderLine, function (inv){
+                    return moment(inv.create_date).format('YYYY-MM-DD') == moment().add(-1,'days').format('YYYY-MM-DD');
+                });
+            }
+            // Mes Actual
+            if ($('#C').is(":checked")){
+                PosOrderLine = _.filter(PosOrderLine, function (inv){
+                    return moment(inv.create_date).format('MM') == moment().format('MM');
+                });
+            }
+            // Mes Pasado
+            if ($('#D').is(":checked")){
+                PosOrderLine = _.filter(PosOrderLine, function (inv){
+                    return moment(inv.create_date).format('MM') == moment().add(-1,'months').format('MM');
+                });
+            }
+            // Rango de fechas
+            if ($('#Z').is(":checked")){
+                $('#datepicker').css('display','block');
+                if (desde.length > 0){
+                    var date = desde.split('/');
+                    PosOrderLine = _.filter(PosOrderLine, function (inv){
+                        return moment(inv.create_date).format('YYYY-MM-DD') >= (date[2]+"-"+date[1]+"-"+date[0]);
+                    });
+                }
+                if (hasta.length > 0){
+                    var date= hasta.split('/');
+                    PosOrderLine = _.filter(PosOrderLine, function (inv){
+                        return moment(inv.create_date).format('YYYY-MM-DD') <= (date[2]+"-"+date[1]+"-"+date[0]);
+                    });
+                }
+            }else{
+                $('#datepicker').css('display','none');
+            }
+
+            return _.flatten(_.filter(PosOrderLine,function (inv) {
+                return inv.product_id[0] === product_id;
+            }));
+        },
+
+
+        // Generar el ranking
+        // Generar el ranking
+        BuildTable: function() {
+            var self = this;
+            var itemProduct;
+            var itemLine;
+            var qty = 0;
+            var ProductProduct = self.ProductProduct;
+            var rankingCab = [];
+            var rankingItem = [];
+            var cat = 0;
+            var itemProductPack;
+            var countSalesOrder = 0;
+            var attribute;
+            var lineUnik;
+
+        //     for (var i = 0; i < self.ProductProduct.length; i++) {
+        //         itemProduct = self.ProductProduct[i];
+        //         itemLine = self.getPosOrderLiners(itemProduct.id);
+        //
+        //         //var itemLine = self.getPosOrderLiners(varitemProduct.id);
+        //               console.log(itemLine);
+        //               if (itemLine.length > 0) {
+        //                   cat = _.reduce(_.map(itemLine, function (map) {
+        //                       return map.qty
+        //                   }), function (meno,num) {
+        //                       return meno + num
+        //                   }, 0);
+        //               }
+        //               //lineUnik = itemLine.shift();
+        //
+        //                   if(itemProduct.attribute_str){
+        //                       attribute = ' ' + itemProduct.attribute_str;
+        //                   }else{
+        //                       attribute = ' ';
+        //                   }
+        //
+        //               rankingItem.push({
+        //                   product_main: itemProduct.name_template+ attribute,
+        //                   price_venta: accounting.formatNumber(itemProduct.lst_price,0,".",","),
+        //                   price_costo: accounting.formatNumber(itemProduct.standard_price,0,".",","),
+        //                   product: "",
+        //                   price_insumo: "",
+        //                   qty_pos: cat,
+        //                   qty: "",
+        //                   subtotal_total_venta: accounting.formatNumber((itemProduct.lst_price*cat),0,".",","),
+        //                   subtotal_total: accounting.formatNumber((itemProduct.standard_price*cat),0,".",","),
+        //                   utilidad: accounting.formatNumber(((itemProduct.lst_price*cat)-(itemProduct.standard_price*cat)),0,".",","),
+        //                   countPack: "",
+        //                   product_main_id: itemProduct.id
+        //               });
+        //
+        //           itemProductPack = self.getProductPack(itemProduct.id);
+        //
+        //           for (var i = 0; i < itemProductPack.length; i++) {
+        //               if (itemProductPack.length > 0){
+        //                   rankingItem.push({
+        //                       product_main: "",
+        //                       price_venta: "",
+        //                       price_costo: "",
+        //                       product: itemProductPack[i].product_id[1],
+        //                       price_insumo: accounting.formatNumber(itemProductPack[i].price,0,".",","),
+        //                       qty_pos: cat,
+        //                       qty: accounting.formatNumber((itemProductPack[i].quantity*cat),3,".",","),
+        //                       subtotal_total_venta: "",
+        //                       subtotal_total: accounting.formatNumber((itemProductPack[i].price*itemProductPack[i].quantity*cat),0,".",","),
+        //                       subtotal: accounting.formatNumber(itemProductPack[i].subtotal,2,".",","),
+        //                       utilidad: "",
+        //                       //create_date: moment(itemLine.create_date).format("YYYY-MM-DD"),
+        //                       countPack: itemProductPack[i].quantity*cat,
+        //                       product_main_id: itemProductPack[i].parent_product_id[0],
+        //                   })
+        //               }
+        //           }
+        //
+        //               // Generar Objeto Principal
+        //               rankingItem=rankingItem.concat(rankingCab);
+        //
+        //     }
+        //
+        //     self.content = rankingItem;
+        //     self.loadTable(rankingItem);
+        //
+        // },
+
+        _.each(ProductProduct, function(item){
+
+            itemLine = self.getPosOrderLiners(item.id);
+                          if (itemLine.length > 0) {
+                              cat = _.reduce(_.map(itemLine, function (map) {
+                                  return map.qty
+                              }), function (meno,num) {
+                                  return meno + num
+                              }, 0);
+                          }
+            if(item.attribute_str){
+                attribute = ' ' + item.attribute_str;
+            }else{
+                attribute = ' ';
+            }
+            itemProductPack = self.getProductPack(item.id);
+
+                          rankingItem.push({
+                              product_main: item.name_template+ attribute,
+                              price_venta: accounting.formatNumber(item.lst_price,0,".",","),
+                              price_costo: accounting.formatNumber(item.standard_price,0,".",","),
+                              product: "",
+                              price_insumo: "",
+                              qty_pos: cat,
+                              qty: "",
+                              subtotal_total_venta: accounting.formatNumber((item.lst_price*cat),0,".",","),
+                              subtotal_total: accounting.formatNumber((item.standard_price*cat),0,".",","),
+                              utilidad: accounting.formatNumber(((item.lst_price*cat)-(item.standard_price*cat)),0,".",","),
+                              countPack: "",
+                              product_main_id: item.id
+                          });
+
+            for (var i = 0; i < itemProductPack.length; i++) {
+
+
+                if (itemProductPack.length > 0){
+                                    rankingItem.push({
+                                        product_main: "",
+                                        price_venta: "",
+                                        price_costo: "",
+                                        product: itemProductPack[i].product_id[1],
+                                        price_insumo: accounting.formatNumber(itemProductPack[i].price,0,".",","),
+                                        qty_pos: cat,
+                                        qty: accounting.formatNumber((itemProductPack[i].quantity*cat),3,".",","),
+                                        subtotal_total_venta: "",
+                                        subtotal_total: accounting.formatNumber((itemProductPack[i].price*itemProductPack[i].quantity*cat),0,".",","),
+                                        subtotal: accounting.formatNumber(itemProductPack[i].subtotal,2,".",","),
+                                        utilidad: "",
+                                        //create_date: moment(itemLine.create_date).format("YYYY-MM-DD"),
+                                        countPack: itemProductPack[i].quantity*cat,
+                                        product_main_id: itemProductPack[i].parent_product_id[0],
+                                    })
+                }
+            }
+
+
+            // Generar Objeto Principal
+            rankingItem=rankingItem.concat(rankingCab);
+
+        });
+
+        self.content = rankingItem;
+        self.loadTable(rankingItem);
+
+     },
+
+        factSearch: function(){
+            var self = this;
+            var product = this.$el.find('#product').val().split('-');
+            var content = self.content;
+
+            if (product != ""){
+                content = _.filter(content, function(inv){
+                    return inv.product_main_id == product[0];
+                });
+            }
+
+            self.loadTable(content)
+        },
+
+        loadTable:function(rowsTable){
+            var self = this;
+            self.rowsData = rowsTable;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load',rowsTable);
+        },
+
+        getObjetPdf: function(rowsTable){
+            var self = this;
+            var rows=self.rowsData;
+
+            return rows;
+        },
+
+        clickOnAction: function (e) {
+            var self = this;
+            var rowsNew;
+            var action = self.$el.find(e.target).val();
+            var table = self.$el.find("#table");
+            var data2 = table.bootstrapTable('getVisibleColumns');
+            var getColumns=[];
+            var rows=[];
+            rowsNew = self.getObjetPdf();
+            if (action === 'pdf') {
+                var dataNEW = _.map(data2, function (val){
+                    return val.field;
+                });
+                _.each(rowsNew,function (item){
+                    rows.push(_.pick(item, dataNEW));
+                });
+                // Obtener los nombre de la Cabezera
+                _.each(_.map(data2,function(val){
+                        return val;
+                    }), function(item){
+                            getColumns.push([{
+                                        title: item.title,
+                                        dataKey: item.field
+                                    }]);
+                });
+                this.drawPDF(_.flatten(getColumns),rows);
+            }
+        },
+        drawPDF: function (getColumns,rows) {
+            var self = this;
+            var fechaActu= new Date();
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new window.jsPDF();
+
+            pdfDoc.autoTable(getColumns, rows, {
+                styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
+                columnStyles: {
+                    product_main : {columnWidth: '6px'},
+                    product : {columnWidth: '8px'},
+                    price_venta: {halign:'right',columnWidth: '6px'},
+                    price_costo: {halign:'right',columnWidth: '6px'},
+                    price_insumo : {halign:'right',columnWidth: '6px'},
+                    qty_pos : {halign:'right',columnWidth: '5px'},
+                    qty : {halign:'right',columnWidth: '5px'},
+                    subtotal_total_venta : {halign:'right',columnWidth: '6px'},
+                    subtotal_total : {halign:'right',columnWidth: '6px'},
+                    utilidad : {halign:'right',columnWidth: '6px'},
+                },
+                margin: { top: 16, horizontal: 7},
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Análisis de Utilidad de Pack de Producto ', data.settings.margin.left, 10);
+                    // FOOTER
+                    var str = "Pagina  " + data.pageCount;
+                    // Total page number plugin only available in jspdf v1.0+
+                    if (typeof pdfDoc.putTotalPages === 'function') {
+                        str = str + " de " + totalPagesExp;
+                    }
+                    pdfDoc.setFontSize(9);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text(str, data.settings.margin.left, pdfDoc.internal.pageSize.height - 5);
+                    }
+            });
+
+            if (typeof pdfDoc.putTotalPages === 'function') {
+                pdfDoc.putTotalPages(totalPagesExp);
+            }
+            pdfDoc.save('Análisis de Utilidad de Pack de Producto.pdf')
+        },
+    });
+}

+ 50 - 0
static/src/reports/report_product_pack.xml

@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportProductPack">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Listado de Receta de Producto</h1>
+            </div>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR</button>
+            <div class="collapse" id="collapseExample">
+                <div class="card card-body">
+                    <br/>
+                    <div class="row">
+                        <div class="col-xs-6">
+                            <div class="panel panel-default">
+                                <div class="panel-heading">Características</div>
+                                <div class="form-group">
+                                    <label for="product">Buscar Producto:</label>
+                                    <input id="product" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ Referencia/ Codigo de barras"/>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <button class="oe_button oe_form_button oe_highlight" value="pdf">PDF</button>
+            </div>
+            <table id="table" class="table_paint_first_row"
+                data-pagination="true"
+                data-toggle="table"
+                data-reorderable-columns="true"
+                data-toolbar="#toolbar"
+                data-show-columns="true"
+                data-buttons-class="oe_button oe_form_button oe_highlight"
+                data-height="auto"
+                data-classes="table table-hover table-condensed"
+                data-row-style="rowStyle"
+                data-search="true">
+                <thead>
+                    <tr>
+                        <th data-field="product_main">Producto</th>
+                        <th data-field="product">Insumo</th>
+                        <th data-field="qty" data-sortable="true" data-align="right">Cantidad</th>
+                    </tr>
+                </thead>
+            </table>
+            <canvas></canvas>
+        </div>
+    </t>
+</template>

+ 94 - 0
static/src/reports/report_product_pack_pos.xml

@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportProductPackPos">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Análisis de ventas POS por insumos</h1>
+                <div id="volver"></div>
+            </div>
+            <div class="collapse" id="collapseExample">
+                <div class="card card-body">
+                    <br/>
+                    <div class="row">
+                      <div class="col-xs-6">
+                      <div class="panel panel-default">
+                      <div class="panel-heading">Fechas</div>
+                      <div class="panel-body">
+                      <ul class="list-unstyled">
+                            <li>
+                                <input type="radio" name="valores" id="X" value="X" checked="checked"/>
+                                <label for="X">Sin Filtro</label>
+                            </li>
+                            <li>
+                                <input type="radio" name="valores" id="A" value="A"/>
+                                <label for="A">Hoy</label>
+                            </li>
+                                                          <li>
+                                                              <input type="radio" name="valores" id="B" value="B"/>
+                                                              <label for="B">Ayer</label>
+                                                          </li>
+                                                          <li>
+                                                              <input type="radio" name="valores" id="C" value="C"/>
+                                                              <label for="C">Mes Actual</label>
+                                                          </li>
+                                                          <li>
+                                                              <input type="radio" name="valores" id="D" value="D"/>
+                                                              <label for="D">Mes Pasado</label>
+                                                          </li>
+                                                          <li>
+                                                              <input type="radio" name="valores" id="Z" value="Z"/>
+                                                              <label for="Z">Busqueda Avanzada</label>
+                                                          </li>
+                                                      </ul>
+                                                      <div id="datepicker" style="display:none;" class="container">
+                                                          <label for="from">Desde: </label>
+                                                          <input type="text"  id="from" name="from"/>
+                                                          <label for="to" >Hasta: </label>
+                                                          <input type="text"  id="to" name="to" />
+                                                      </div>
+                                                  </div>
+                                              </div>
+                                          </div>
+
+
+
+                        <div class="col-xs-6">
+                            <div class="panel panel-default">
+                                <div class="panel-heading">Características</div>
+                                <div class="form-group">
+                                    <label for="product">Buscar Producto:</label>
+                                    <input id="product" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ Referencia/ Codigo de barras"/>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <button type="button" class="oe_button oe_form_button oe_highlight btn-block" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR</button>
+                <button class="oe_button oe_form_button oe_highlight btn-block" value="pdf">PDF</button>
+            </div>
+            <table id="table" class="table_paint_first_row"
+                data-pagination="true"
+                data-toggle="table"
+                data-reorderable-columns="true"
+                data-toolbar="#toolbar"
+                data-show-columns="true"
+                data-buttons-class="oe_button oe_form_button oe_highlight"
+                data-height="auto"
+                data-classes="table table-hover table-condensed"
+                data-row-style="rowStyle"
+                data-search="true">
+                <thead>
+                    <tr>
+                        <th data-field="product_main">Producto</th>
+                        <th data-field="product">Insumo</th>
+                        <th data-field="qty_pos" data-sortable="true" data-align="right">Cant. Venta</th>
+                        <th data-field="qty" data-sortable="true" data-align="right">Cantidad Restado</th>
+                    </tr>
+                </thead>
+            </table>
+            <canvas></canvas>
+        </div>
+    </t>
+</template>

+ 58 - 0
static/src/reports/report_product_pack_utilidad.xml

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportProductPackUtilidad">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Análisis de Utilidad de Pack de Producto</h1>
+                <div id="volver"></div>
+            </div>
+            <div class="collapse" id="collapseExample">
+                <div class="card card-body">
+                    <br/>
+                    <div class="row">
+                        <div class="col-xs-6">
+                            <div class="panel panel-default">
+                                <div class="panel-heading">Características</div>
+                                <div class="form-group">
+                                    <label for="product">Buscar Producto:</label>
+                                    <input id="product" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ Referencia/ Codigo de barras"/>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <button type="button" class="oe_button oe_form_button oe_highlight btn-block" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR</button>
+                <button class="oe_button oe_form_button oe_highlight btn-block" value="pdf">PDF</button>
+            </div>
+            <table id="table" class="table_paint_first_row"
+                data-pagination="true"
+                data-toggle="table"
+                data-reorderable-columns="true"
+                data-toolbar="#toolbar"
+                data-show-columns="true"
+                data-buttons-class="oe_button oe_form_button oe_highlight"
+                data-height="auto"
+                data-classes="table table-hover table-condensed"
+                data-row-style="rowStyle"
+                data-search="true">
+                <thead>
+                    <tr>
+                        <th data-field="product_main">Producto</th>
+                        <th data-field="product">Insumo</th>
+                        <th data-field="price_venta" data-align="right">P.Venta</th>
+                        <th data-field="price_costo" data-align="right">P.Costo</th>
+                        <th data-field="price_insumo" data-align="right">P.C.Insumo</th>
+                        <th data-field="qty_pos" data-sortable="true" data-align="right">Cant. Venta</th>
+                        <th data-field="qty" data-sortable="true" data-align="right">Cantidad</th>
+                        <th data-field="subtotal_total_venta" data-align="right">Total Venta</th>
+                        <th data-field="subtotal_total" data-align="right">Total Compra</th>
+                        <th data-field="utilidad" data-align="right">Utilidad</th>
+                    </tr>
+                </thead>
+            </table>
+            <canvas></canvas>
+        </div>
+    </t>
+</template>

+ 5 - 0
static/src/xml/eiru_reporting.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<template xml:space="preserve">
+
+</template>

+ 5 - 0
static/src/xml/eiru_reporting_base.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<template xml:space="preserve">
+    
+</template>

+ 27 - 0
templates.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+  <data>
+    <template id="eiru_reports_mrp_assets" inherit_id="eiru_assets.assets">
+      <xpath expr="." position="inside">
+        <link rel="stylesheet" href="/eiru_reports_pack/static/src/css/custom.css"/>
+
+        <!-- configuration < main > -->
+        <script type="text/javascript" src="/eiru_reports_pack/static/src/js/main.js"/>
+        <script type="text/javascript" src="/eiru_reports_pack/static/src/js/reporting_base.js"/>
+
+        <!-- Listado de tareas -->
+
+        <script type="text/javascript" src="/eiru_reports_pack/static/src/js/reports/report_product_pack.js"/>
+
+        <!-- Análisis de producción -->
+
+        <script type="text/javascript" src="/eiru_reports_pack/static/src/js/reports/report_product_pack_utilidad.js"/>
+
+        <!-- Análisis de producción -->
+
+        <script type="text/javascript" src="/eiru_reports_pack/static/src/js/reports/report_product_pack_pos.js"/>
+
+      </xpath>
+    </template>
+  </data>
+</openerp>

+ 24 - 0
views/actions.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+
+		<!-- Analisis de Pack de Productos -->
+		<record id="product_pack_report_action" model="ir.actions.client">
+			<field name="name">Analisis de Pack de Productos</field>
+			<field name="tag">eiru_reports_pack.product_pack_report_action</field>
+		</record>
+
+		<!-- Analisis de Utilidad de Pack de Producto -->
+		<record id="mrp_utilidad_report_action" model="ir.actions.client">
+			<field name="name">Analisis de Utilidad de Pack de Producto</field>
+			<field name="tag">eiru_reports_pack.mrp_utilidad_report_action</field>
+		</record>
+
+		<!-- Analisis de Pack de Productos -->
+		<record id="product_packpos_report_action" model="ir.actions.client">
+			<field name="name">Analisis de receta por ventas POS</field>
+			<field name="tag">eiru_reports_pack.product_packpos_report_action</field>
+		</record>
+
+	</data>
+</openerp>

+ 20 - 0
views/menus.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+  <data>
+    <!-- main menu -->
+    <menuitem id="pack_parent_menu" name="Informes Pack" parent="eiru_reports.sale_parent_menu" sequence="200"/>
+
+    <!-- sub menu -->
+
+       <!-- Analisis de pack de productos -->
+            <menuitem id="product_pack_report_menu_submenu" parent="pack_parent_menu" name="Analisis de Pack de Productos" action="product_pack_report_action" sequence="4"/>
+
+            <!-- Listado de produccion de pack utilidad -->
+            <menuitem id="mrp_utilidad_report_menu_submenu" parent="pack_parent_menu" name="Analisis de Utilidad de Pack de Producto" action="mrp_utilidad_report_action" sequence="5"/>
+
+            <!-- Analisis de pack de productos -->
+            <menuitem id="product_packpos_report_menu_submenu" parent="pack_parent_menu" name="Analisis de ventas Pos por insumos" action="product_packpos_report_action" sequence="6"/>
+
+
+  </data>
+</openerp>