Browse Source

FIX ADD Agregado report de utilidad sobre precio de ventas

Sebas 6 years ago
parent
commit
15a2c64e59

+ 30 - 40
static/src/js/reports/report_invoice_difventa.js

@@ -115,12 +115,9 @@ function report_invoice_difventa (reporting){
         // Cansultar
         submitForm: function () {
             var self = this;
-            this.fetchCurency().then(function(Currency) {
-                self.Currency = Currency;
-                return Currency;
-            }).then(function (Currency) {
-               return self.fecthResStore();
-            }).then(function(ResStore){
+            self.fecthResStore().then(function(ResStore) {
+                return ResStore;
+            }).then(function (ResStore) {
                 self.ResStore = ResStore;
                 self.$el.find('#current-store').append('<option value="9999999">Todas las SUC.</option>');
                 _.each(ResStore,function(item){
@@ -141,8 +138,11 @@ function report_invoice_difventa (reporting){
                 return self.fecthCompanyCurrency();
             }).then(function(resCompany){
                 self.resCompany = resCompany;
+                return self.fetchResCurrency();
+            }).then(function(ResCurrency) {
+                self.ResCurrency = ResCurrency;
                 self.searchProduct();
-                return self.invoice_Currency();
+                return self.fectUtility();
             });
         },
 
@@ -206,22 +206,23 @@ function report_invoice_difventa (reporting){
         fecthCompanyCurrency: function(){
             var self = this;
             var defer = $.Deferred();
-            var currency = new model.web.Model('res.company');
-            var field=['id', 'currency_id'];
-            var domain=[['id','=',1]];
-            currency.query(field).filter(domain).all().then(function(results){
+            var field=['id','name', 'currency_id'];
+            var domain = [['id', '=', self.session.company_id]];
+            var ResCompany = new model.web.Model('res.company');
+            ResCompany.query(field).filter(domain).all().then(function(results){
                 defer.resolve(results);
             });
             return defer;
         },
 
         // Buscar Cambio de Monedas USD,PYG,ARG,BRL
-        fetchCurency: function () {
+        fetchResCurrency : function(){
+            var self = this;
             var defer = $.Deferred();
-            var currency_Rate = new model.web.Model('res.currency.rate');
-            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
-            var domain = [['currency_id', 'in', [166 , 20, 7, 3]]];
-            currency_Rate.query(fields).filter(domain).all().then(function (results) {
+            var fields = ['id','name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
+            var domain = [['active', '=', true]];
+            var ResCurrency = new model.web.Model('res.currency');
+            ResCurrency.query(fields).filter(domain).all().then(function(results) {
                 defer.resolve(results);
             });
             return defer;
@@ -230,7 +231,7 @@ function report_invoice_difventa (reporting){
         // Invoice (FACTURAS)
         fetchInvoiceV2: function () {
             var self = this;
-            var filter ="[['state', 'in',['open','paid']],['type', '=', 'out_invoice']";
+            var filter ="[['state', 'in',['open','paid']],['type', '=', 'out_invoice']]";
             var journal_ids = _.flatten(_.map(self.AccountJournal, function (item) {
                 return item.id;
             }));
@@ -275,26 +276,11 @@ function report_invoice_difventa (reporting){
         },
 
         // Obtener Monedas de la Factura
-        getCurrency: function (id){
-            return _.find(this.Currency,function (curr) {
-                return _.contains(curr.currency_id,id);
-            });
-        },
-
-        // Actualizar cambio de las moneda de Factura
-        invoice_Currency: function(){
-            for (var i = 0; i < this.invoices.length; i++) {
-                var currency_new;
-                var item = this.invoices[i];
-                var id = item.currency_id[0];
-                currency_new = this.getCurrency(id);
-                if (!currency_new){
-                    currency_new={};
-                    currency_new.rate=1;
-                }
-                this.invoices[i].rate=(currency_new.rate);
-            }
-            return this.fectUtility();
+        getResCurrency: function (id) {
+            var self = this;
+            return _.filter(self.ResCurrency,function (item) {
+                return item.id === id;
+            })
         },
 
         // Obtener la Detalles de la Factura
@@ -322,19 +308,23 @@ function report_invoice_difventa (reporting){
         fectUtility: function(){
             var self = this;
             var data=[];
+            var CurrencyBase = self.getResCurrency(self.resCompany[0].currency_id[0]).shift();
             var item;
             var invoice;
             var producto;
 
             for (var i = 0; i < this.invoiceLines.length; i++) {
                 item = this.invoiceLines[i];
+
                 invoice = this.getInvoice(item.id);
+                var currency = self.getResCurrency(invoice.currency_id[0]).shift();
                 producto =this.getProduct(item.product_id);
 
                 if (!producto){
                     producto={};
                     producto.standard_price=0;
                 }
+
                 var store_id = self.getAccountJournal(invoice.journal_id[0]);
                 if(store_id.length > 0){
                     data.push({
@@ -344,9 +334,9 @@ function report_invoice_difventa (reporting){
                         name : (item.name),
                         quantity : accounting.formatNumber((item.quantity),0, ".", ","),
                         price_unity : accounting.formatNumber((producto.lst_price),2, ".", ","),
-                        standar_price : accounting.formatNumber((item.price_unit / invoice.rate),2, ".", ","),
-                        utility : accounting.formatNumber(((item.price_unit / invoice.rate) - (producto.lst_price)),2, ".", ","),
-                        utility_porc: accounting.formatNumber(((((item.price_unit / invoice.rate)*100)/(producto.lst_price))-100),0, ".", ","),
+                        standar_price : accounting.formatNumber((item.price_unit*(CurrencyBase.rate_silent/currency.rate_silent)),2, ".", ","),
+                        utility : accounting.formatNumber(((item.price_unit*(CurrencyBase.rate_silent/currency.rate_silent)) - (producto.lst_price)),2, ".", ","),
+                        utility_porc: accounting.formatNumber(((((item.price_unit*(CurrencyBase.rate_silent/currency.rate_silent))*100)/(producto.lst_price))-100),0, ".", ","),
                         journal_id :(invoice.journal_id[0]),
                         journal_name :(invoice.journal_id[1]),
                         date_create :moment(invoice.date_invoice).format("DD/MM/YYYY"),

+ 591 - 0
static/src/js/reports/report_normal_pos_utilidad.js

@@ -0,0 +1,591 @@
+function report_normal_pos_utilidad(reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportNormalPosUtilidadWidget = reporting.Base.extend({
+        template: 'ReportNormalPosUtilidad',
+        content: [],
+        rowsData :[],
+        modules:[],
+
+        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',
+            'change #user' : 'factSearch',
+            'change #current-journal' : 'factSearch',
+            'change #current-store' : 'factSearch',
+            'click-row.bs.table #table ' : 'ckickAnalysisDetail',
+        },
+
+        init : function(parent){
+            this._super(parent);
+        },
+
+        start: function () {
+            var self = this;
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.rowsData});
+            this.submitForm();
+        },
+
+        submitForm: function () {
+            var self = this;
+            self.fetchPosOrder().then(function(PosOrder){
+                return PosOrder;
+            }).then(function(PosOrder) {
+                self.PosOrder = PosOrder;
+                return self.fetchPosOrderLine();
+            }).then(function (PosOrderLine){
+                self.PosOrderLine = PosOrderLine;
+                return self.fetchAccountInvoice();
+            }).then(function (AccountInvoice){
+                self.AccountInvoice = AccountInvoice;
+                return self.fetchAccountInvoiceLine();
+            }).then(function (AccountInvoiceLine){
+                self.AccountInvoiceLine = AccountInvoiceLine;
+                return self.fetchProductProduct();
+            }).then(function (ProductProduct){
+                self.ProductProduct = ProductProduct;
+                return self.fetchAccountPeriod();
+            }).then(function (AccountPeriod){
+                self.AccountPeriod = AccountPeriod;
+                return self.fecthAccountJournal();
+            }).then(function(AccountJournal){
+                self.AccountJournal = AccountJournal;
+                return self.fetchResCompany();
+            }).then(function(ResCompany) {
+                self.ResCompany = ResCompany;
+                return self.fetchResCurrency();
+            }).then(function(ResCurrency) {
+                self.ResCurrency = ResCurrency;
+                return self.showMonth();
+            });
+        },
+
+        /*=============
+            POS ORDER
+        =============*/
+        fetchPosOrder: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var domain =[['state', 'in',['done','paid','invoiced']]];
+            var field =['id', 'partner_id','name', 'session_id', 'state', 'table_id', 'statement_ids','create_date','amount_total','user_id','amount_tax','sale_journal','date_order'];
+            var PosOrder = new instance.web.Model('pos.order');
+            PosOrder.query(field).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        /*==================
+            POS ORDER LINE
+        ==================*/
+        fetchPosOrderLine: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var order_ids = _.flatten(_.map(self.PosOrder, function (item) {
+                return item.id;
+            }));
+            var domain =[['order_id', 'in',order_ids]];
+            var field =['id', 'product_id','order_id'];
+            var PosOrderLine = new instance.web.Model('pos.order.line');
+            PosOrderLine.query(field).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        /*===================
+            ACCOUNT INVOICE
+        ===================*/
+        fetchAccountInvoice: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var domain = [['state','in',['open','paid']]];
+            var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'date_invoice','amount_total','amount_tax','amount_untaxed'];
+            var AccountInvoice = new instance.web.Model('account.invoice');
+            AccountInvoice.query(field).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        /*========================
+            ACCOUNT INVOICE LINE
+        ========================*/
+        fetchAccountInvoiceLine: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var invoice_ids = _.flatten(_.map(self.AccountInvoice, function (item) {
+                return item.id;
+            }));
+            var domain = [['invoice_id','in',invoice_ids]];
+            var field =['id', 'product_id','invoice_id'];
+            var AccountInvoiceLine = new instance.web.Model('account.invoice.line');
+            AccountInvoiceLine.query(field).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        /*===================
+            PRODUCT PRODUCT
+        ===================*/
+        fetchProductProduct: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var field =['id', 'name','standard_price'];
+            var ProductProduct = new instance.web.Model('product.product');
+            ProductProduct.query(field).filter().all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        /*==================
+            ACCOUNT PERIOD
+        ==================*/
+        fetchAccountPeriod: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var domain = [['special','=',false]];
+            var field =['id', 'name', 'date_start'];
+            var AccountPeriod = new instance.web.Model('account.period');
+            AccountPeriod.query(field).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        /*===================
+            ACCOUNT JOURNAL
+        ===================*/
+        fecthAccountJournal: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var field = ['id', 'name','store_ids','type'];
+            var domain = [['active','=',true],['type','in',['sale','sale_refund']]];
+            var AccountJournal = new instance.web.Model('account.journal');
+            AccountJournal.query(field).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        /*===============
+            RES COMPANY
+        ===============*/
+        fetchResCompany: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var fields = ['id','name', 'currency_id'];
+            var domain = [['id', '=', self.session.company_id]];
+            var ResCompany = new instance.web.Model('res.company');
+            ResCompany.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        /*================
+            RES CURRENCY
+        ================*/
+        fetchResCurrency : function(){
+            var self = this;
+            var defer = $.Deferred();
+            var fields = ['id','name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
+            var domain = [['active', '=', true]];
+            var ResCurrency = new instance.web.Model('res.currency');
+            ResCurrency.query(fields).filter(domain).all().then(function(results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        /*=============================
+            GET CURRENCY BASE DETAILS
+        ===============================*/
+        getResCurrency: function (id) {
+            var self = this;
+            return _.filter(self.ResCurrency,function (item) {
+                return item.id === id;
+            })
+        },
+
+        /*======================
+            POS ORDER BY MONTH
+        ======================*/
+        getMonthPosOrder:function(mes) {
+            var self = this;
+            return _.flatten(_.filter(self.PosOrder,function (inv) {
+                var utc = moment.utc(inv.date_order,'YYYY-MM-DD h:mm:ss A');
+                return moment(utc._d).format('YYYY-MM') === moment(mes).format('YYYY-MM');
+            }));
+        },
+
+        /*======================
+            GET POS ORDER LINE
+        ======================*/
+        getPosOrderLine:function(order) {
+            var self = this;
+            var order_ids = _.flatten(_.map(order, function (item) {
+                return item.id;
+            }));
+            return _.flatten(_.filter(self.PosOrderLine,function (inv) {
+                return _.contains(order_ids, inv.order_id[0]);
+            }));
+        },
+
+        /*============================
+            ACCOUNT INVOICE BY MONTH
+        ============================*/
+        getMonthAccountInvoice:function(mes, type) {
+            var self = this;
+            var journals  = _.filter(self.AccountJournal,function (inv) {
+                return inv.type == type;
+            });
+            if(journals.length > 0){
+                var journal_ids = _.flatten(_.map(journals, function (item) {
+                    return item.id;
+                }));
+                return _.flatten(_.filter(self.AccountInvoice,function (inv) {
+                    return moment(inv.date_invoice).format('YYYY-MM') === moment(mes).format('YYYY-MM') & _.contains(journal_ids, inv.journal_id[0]);
+                }));
+            }
+        },
+
+        /*============================
+            GET ACCOUNT INVOICE LINE
+        ============================*/
+        getAccountInvoiceLine:function(invoice) {
+            var self = this;
+            var invoice_ids = _.flatten(_.map(invoice, function (item) {
+                return item.id;
+            }));
+            return _.flatten(_.filter(self.AccountInvoiceLine,function (inv) {
+                return _.contains(invoice_ids, inv.invoice_id[0]);
+            }));
+        },
+
+        /*=======================
+            GET PRODUCT PRODUCT
+        =======================*/
+        getProductProduct: function (id) {
+            var self = this;
+            return _.filter(self.ProductProduct,function (item) {
+                return item.id === id;
+            })
+        },
+
+        /*==============
+            GET LINES
+        ==============*/
+        getCost:function(lines) {
+            var self = this;
+            var data = [];
+            var product;
+            _.each(lines, function (item) {
+                product = self.getProductProduct(item.product_id[0]);
+                data.push({
+                    name: product[0].name,
+                    standard_price: product[0].standard_price,
+                })
+            });
+            var total = _.reduce(_.map(data,function(item) {
+                return item.standard_price;
+            }),function(memo, num) {
+                return memo + num;
+            },0);
+            return total;
+        },
+
+        /*=========
+            BUILD
+        =========*/
+        showMonth: function() {
+            var self = this;
+            var AccountPeriod = self.AccountPeriod;
+            var order;
+            var order_line;
+            var invoice;
+            var invoice_line;
+            var invoice_refund;
+            var title = [];
+            var body = [];
+            var data = [];
+            var array = [];
+            var order_cost = 0;
+            var invoice_cost = 0;
+            var total_cost = 0;
+            var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
+            _.each(AccountPeriod, function (index) {
+
+                order = self.getMonthPosOrder(index.date_start);
+                order_line = self.getPosOrderLine(order);
+                order_cost = self.getCost(order_line);
+
+                invoice = self.getMonthAccountInvoice(index.date_start, 'sale');
+                invoice_line = self.getAccountInvoiceLine(invoice);
+                invoice_cost = self.getCost(invoice_line);
+
+                invoice_refund = self.getMonthAccountInvoice(index.date_start, 'sale_refund');
+
+                total_cost = order_cost + invoice_cost;
+
+                /*=============
+                    POS ORDER
+                =============*/
+                var order_total_tax = _.reduce(_.map(order,function(item) {
+                    return item.amount_tax;
+                }),function(memo, num) {
+                    return memo + num;
+                },0);
+
+                var order_total = _.reduce(_.map(order,function(item) {
+                    return item.amount_total;
+                }),function(memo, num) {
+                    return memo + num;
+                },0);
+
+                var order_total_untaxed = order_total - order_total_tax;
+
+
+                /*================
+                    SALE INVOICE
+                ================*/
+                array = [];
+                _.each(invoice, function (item) {
+                    var currency = self.getResCurrency(item.currency_id[0]).shift();
+                    array.push({
+                        amount_untaxed: item.amount_untaxed * (CurrencyBase.rate_silent / currency.rate_silent),
+                        amount_tax: item.amount_tax * (CurrencyBase.rate_silent / currency.rate_silent),
+                        amount_total: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
+                    })
+                });
+                var invoice_total_untaxed = 0;
+                var invoice_total_tax = 0;
+                var invoice_total = 0;
+                if(array.length > 0){
+                    /*===========
+                        UNTAXED
+                    ===========*/
+                    invoice_total_untaxed = _.reduce(_.map(array, function (map) {
+                        return map.amount_untaxed;
+                    }), function (memo, num) {
+                        return memo + num;
+                    });
+
+                    /*===========
+                        TAXED
+                    ===========*/
+                    invoice_total_tax = _.reduce(_.map(array, function (map) {
+                        return map.amount_tax;
+                    }), function (memo, num) {
+                        return memo + num;
+                    });
+
+                    /*=========
+                        TOTAL
+                    =========*/
+                    invoice_total = _.reduce(_.map(array, function (map) {
+                        return map.amount_total;
+                    }), function (memo, num) {
+                        return memo + num;
+                    });
+                }
+
+                /*===============
+                    SALE REFUND
+                ===============*/
+                array = [];
+                _.each(invoice_refund, function (item) {
+                    var currency = self.getResCurrency(item.currency_id[0]).shift();
+                    array.push({
+                        amount_untaxed: item.amount_untaxed * (CurrencyBase.rate_silent / currency.rate_silent),
+                        amount_tax: item.amount_tax * (CurrencyBase.rate_silent / currency.rate_silent),
+                        amount_total: item.amount_total * (CurrencyBase.rate_silent / currency.rate_silent),
+                    })
+                });
+                var invoice_refund_total_untaxed = 0;
+                var invoice_refund_total_tax = 0;
+                var invoice_refund_total = 0;
+                if(array.length > 0){
+                    /*===========
+                        UNTAXED
+                    ===========*/
+                    invoice_refund_total_untaxed = _.reduce(_.map(array, function (map) {
+                        return map.amount_untaxed;
+                    }), function (memo, num) {
+                        return memo + num;
+                    });
+
+                    /*===========
+                        TAXED
+                    ===========*/
+                    invoice_refund_total_tax = _.reduce(_.map(array, function (map) {
+                        return map.amount_tax;
+                    }), function (memo, num) {
+                        return memo + num;
+                    });
+
+                    /*=========
+                        TOTAL
+                    =========*/
+                    invoice_refund_total = _.reduce(_.map(array, function (map) {
+                        return map.amount_total;
+                    }), function (memo, num) {
+                        return memo + num;
+                    });
+                }
+
+                /*======================
+                    SALE UNTAXED TOTAL
+                ======================*/
+                var sale_untaxed_total = order_total_untaxed + invoice_total_untaxed - invoice_refund_total_untaxed;
+
+                /*====================
+                    SALE TAXED TOTAL
+                ====================*/
+                var sale_tax_total = order_total_tax + invoice_total_tax - invoice_refund_total_tax;
+
+                /*==============
+                    SALE TOTAL
+                ==============*/
+                var sale_total = order_total + invoice_total - invoice_refund_total;
+
+                /*=============
+                    BENEFICIO
+                =============*/
+                var profit = sale_untaxed_total - total_cost;
+
+                /*==========
+                    MARGIN
+                ==========*/
+
+                var margin = (total_cost * 100)/sale_untaxed_total;
+                margin = 100 - margin;
+
+                if(sale_untaxed_total > 0 || sale_tax_total > 0 || sale_total > 0){
+                    data.push({
+                        name: index.name,
+                        subtotal: accounting.formatMoney(sale_untaxed_total, CurrencyBase.symbol, 2, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                        tax: accounting.formatMoney(sale_tax_total, CurrencyBase.symbol, 2, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                        cost: accounting.formatMoney(total_cost, CurrencyBase.symbol, 2, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                        margin: accounting.formatNumber(margin,2,".",",") + '%',
+                        total: accounting.formatMoney(sale_total, CurrencyBase.symbol, 2, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                        profit: accounting.formatMoney(profit, CurrencyBase.symbol, 2, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    });
+                }
+
+                body.push(sale_total);
+                title.push(index.name);
+
+            });
+            self.loadTable(data);
+            self.fetchChart(title,body,CurrencyBase);
+        },
+
+        loadTable:function(rowsTable){
+            var self = this;
+            self.rowsData = rowsTable;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load',rowsTable);
+        },
+
+        /*===============
+            BUILD CHART
+        ===============*/
+        fetchChart: function (title,body,CurrencyBase) {
+            var self = this;
+            var label = title;
+            var body = body;
+
+            Chart.scaleService.updateScaleDefaults('linear', {
+              ticks: {
+                callback: function(tick) {
+                    return tick.toLocaleString('de-DE');
+                }
+              }
+            });
+
+            Chart.defaults.global.tooltips.callbacks.label = function(tooltipItem, data) {
+                var dataset = data.datasets[tooltipItem.datasetIndex];
+                var datasetLabel = dataset.label || '';
+                return datasetLabel +  dataset.data[tooltipItem.index].toLocaleString('de-DE');
+            };
+
+            var chart = new Chart($('.reporting-chart'), {
+                type: 'line',
+                data: {
+                    labels: label,
+                    datasets: [
+                        {
+                            label: false,
+                            data: body,
+                            backgroundColor: '#bbdefb',
+                            borderColor: '#0288d1',
+                            borderWidth: 1,
+                            fill: true,
+                            datalabels : {
+                                align   : 'end',
+                                anchor : 'end',
+                                display: true,
+                                backgroundColor: function(context) {
+                                    return context.dataset.backgroundColor;
+                                },
+                                borderRadius: 4,
+                                color: '#001f3f',
+                                font: {
+                                    weight: 'bold'
+                                }
+                            }
+                        }
+                    ]
+                },
+                options: {
+                    responsive: true,
+                    responsiveAnimationDuration:10,
+                    maintainAspectRatio:false,
+
+                    title: {
+                        display: false,
+                    },
+                    legend: {
+                       display: false,
+                    },
+                    layout: {
+                        padding: {
+                            top: 0,
+                            bottom: 45,
+                            left : 0,
+                            rigth: 0,
+                        }
+                    },
+                    events: ['click'],
+                    tooltips: {
+                        callbacks: {
+                            label: function(tooltipItem, data) {
+                                var label = data.datasets[tooltipItem.datasetIndex].label || '';
+
+                                if (label) {
+                                    label += ': ';
+                                }
+                                label += accounting.formatMoney(tooltipItem.yLabel, CurrencyBase.symbol, CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator);
+                                return label;
+                            }
+                        }
+                    }
+                }
+            });
+        },
+
+    });
+}

+ 20 - 7
static/src/js/reports/report_product_pack.js

@@ -228,10 +228,28 @@ function report_product_pack (reporting) {
             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: "",
@@ -242,13 +260,8 @@ function report_product_pack (reporting) {
                         })
                     }
                 }
-                rankingItem.unshift({
-                    product_main: item.name_template,
-                    product: "",
-                    qty: "",
-                    countPack: "",
-                    product_main_id: item.id
-                });
+
+
                 // Generar Objeto Principal
                 rankingItem=rankingItem.concat(rankingCab);
 

+ 29 - 26
static/src/js/reports/report_product_pack_utilidad.js

@@ -180,11 +180,10 @@ function report_product_pack_utilidad (reporting) {
             return defer;
         },
 
-        // Obtener Pedido
+        // Obtener Pedido ,['id', 'in', ['1065','1067']]
         fecthPosOrder: function() {
             var self = this;
             var defer = $.Deferred();
-            var hoy = moment().format('2018-05-24');
             var modules = self.checkModel('point_of_sale');
 
             if (modules.length <= 0){
@@ -193,7 +192,7 @@ function report_product_pack_utilidad (reporting) {
             }
 
             var fields = ['id', 'lines', 'date_order'];
-            var domain = [ ['state', 'in', ['paid','done','invoiced']],['date_order','>=', hoy]];
+            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);
@@ -217,7 +216,7 @@ function report_product_pack_utilidad (reporting) {
 
             return defer;
         },
-        // Obtener Productos ['id', 'in', product_id],
+        // Obtener Productos ,['id', '=', 110]
         fetchProductProduct: function (PosOrderLine) {
             var self = this;
 
@@ -268,7 +267,7 @@ function report_product_pack_utilidad (reporting) {
         getProductPack: function(id){
             var self = this;
             return _.filter(self.productPack,function (item) {
-                return item.id == id;
+                return item.parent_product_id[0] == id;
             });
         },
 
@@ -383,24 +382,41 @@ function report_product_pack_utilidad (reporting) {
 
             for (var i = 0; i < self.ProductProduct.length; i++) {
                 itemProduct = self.ProductProduct[i];
+
                 itemLine = self.getPosOrderLiners(itemProduct.id);
+
                 if (itemLine.length > 0) {
                     cat = _.reduce(_.map(itemLine, function (map) {
                         return map.qty
                     }), function (meno,num) {
                         return meno + num
                     }, 0);
+                }
+                //     lineUnik = itemLine.shift();
 
-                    lineUnik = itemLine.shift();
-
-                    if(itemProduct.attribute_str){
-                        attribute = '*' + itemProduct.attribute_str;
-                    }else{
-                        attribute = ' ';
-                    }
+                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({
@@ -421,20 +437,7 @@ function report_product_pack_utilidad (reporting) {
                         })
                     }
                 }
-                rankingItem.unshift({
-                    product_main: itemProduct.name_template,
-                    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
-                });
+
                     // Generar Objeto Principal
                     rankingItem=rankingItem.concat(rankingCab);
 

+ 40 - 0
static/src/reports/report_normal_pos_utilidad.xml

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportNormalPosUtilidad">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Ventas</h1>
+            </div>
+            <div class="chart-container center-block" style="height:300px;width:90%;">
+                <canvas class="reporting-chart"></canvas>    
+            </div>
+            <div class="container" style="width:90%;">
+                <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="name" data-sortable="true" data-align="center">Periodo</th>
+                            <th data-field="subtotal" data-sortable="true" data-align="right">Subtotal</th>
+                            <th data-field="tax" data-align="right">Impuestos</th>
+                            <th data-field="cost" data-sortable="true" data-align="right">Coste</th>
+                            <th data-field="margin" data-sortable="true" data-align="center">Margen</th>
+                            <th data-field="total" data-sortable="true" data-align="right">Total</th>
+                            <th data-field="profit" data-sortable="true" data-align="right">Beneficio</th>
+                        </tr>
+                    </thead>
+                </table>
+            </div>
+
+            <div id="dialog"></div>
+        </div>
+    </t>
+</template>

+ 2 - 3
static/src/reports/report_product_pack.xml

@@ -4,8 +4,8 @@
         <div class="report_view">
             <div class="reporting_page_header">
                 <h1>Listado de Receta de Producto</h1>
-                <div id="volver"></div>
             </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/>
@@ -23,8 +23,7 @@
                 </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>
+                <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"