Procházet zdrojové kódy

EXtension eiru reports para crm

Sebas před 6 roky
revize
f4a5ed6098

+ 3 - 0
__init__.py

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

binární
__init__.pyc


+ 24 - 0
__openerp__.py

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

+ 2 - 0
controllers.py

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

binární
controllers.pyc


+ 181 - 0
models.py

@@ -0,0 +1,181 @@
+# -*- coding: utf-8 -*-
+
+from openerp import models, fields, api
+
+class AccountInvoice(models.Model):
+	_inherit = 'account.invoice'
+
+	############################################################
+	#	ACCOUNT INVOICE
+	############################################################
+
+	@api.model
+	def getAccountInvoice(self,domain):
+		AccountInvoice = self.env['account.invoice'].search(domain)
+		decimal_precision = self.env['decimal.precision'].precision_get('Account')
+		values = []
+		for invoice in AccountInvoice:
+			values.append({
+				'id': invoice.id,
+				'type': invoice.type,
+				'state': invoice.state,
+				'number': invoice.number,
+				'journal_id': [
+					invoice.journal_id.id,
+					invoice.journal_id.name
+				],
+				'invoice_currency': [
+					invoice.currency_id.id,
+					invoice.currency_id.name,
+					invoice.currency_id.rate
+				],
+				'company_currency': [
+					invoice.company_id.currency_id.id,
+					invoice.company_id.currency_id.name,
+					invoice.company_id.currency_id.rate
+				],
+				'date_invoice': invoice.date_invoice,
+				'date_due': invoice.date_invoice,
+				'partner_id': [
+					invoice.partner_id.id,
+					invoice.partner_id.name,
+				],
+				'supplier_invoice_number': invoice.supplier_invoice_number,
+				'user_id': [
+					invoice.user_id.id,
+					invoice.user_id.name
+				],
+                'period_id': [
+                	invoice.period_id.id,
+                	invoice.period_id.name
+                ],
+				'origin': invoice.origin,
+				'reference': invoice.reference,
+				'payment_term': {
+					'id' : invoice.payment_term.id,
+					'name' : invoice.payment_term.name,
+					'check_credit' : invoice.payment_term.check_credit,
+					},
+                'amount_untaxed': invoice.amount_untaxed,
+                'residual': invoice.residual,
+                'amount_tax': invoice.amount_tax,
+				'amount_total': invoice.amount_total,
+				'amount_untaxed_currency': invoice.amount_untaxed * (invoice.company_id.currency_id.rate / invoice.currency_id.rate),
+				'residual_currency': invoice.residual * (invoice.company_id.currency_id.rate / invoice.currency_id.rate),
+				'amount_tax_currency': invoice.amount_tax * (invoice.company_id.currency_id.rate / invoice.currency_id.rate),
+				'amount_total_currency': invoice.amount_total * (invoice.company_id.currency_id.rate / invoice.currency_id.rate),
+			})
+
+		return values
+
+class AccountInvoiceLine(models.Model):
+	_inherit = 'account.invoice.line'
+
+	############################################################
+	#	ACCOUNT INVOICE LINE
+	############################################################
+
+	@api.model
+	def getAccountInvoiceLine(self,domain):
+		AccountInvoiceLine = self.env['account.invoice.line'].search(domain)
+		decimal_precision = self.env['decimal.precision'].precision_get('Account')
+		values = []
+		for line in AccountInvoiceLine:
+			values.append({
+				'id': line.id,
+				'invoice_id':line.invoice_id.id,
+				'journal_id' : line.invoice_id.journal_id.id,
+				'product_id': {
+					'id' : line.product_id.id,
+					'name' : line.product_id.display_name,
+				},
+				'name' : line.name,
+				'price_unit': line.price_unit,
+				'price_subtotal': line.price_subtotal,
+				'quantity' : line.quantity,
+				'company_currency':[
+					line.invoice_id.company_id.currency_id.id,
+					line.invoice_id.company_id.currency_id.name,
+					line.invoice_id.company_id.currency_id.rate,
+				],
+				'invoice_currency':[
+					line.invoice_id.currency_id.id,
+					line.invoice_id.currency_id.name,
+					line.invoice_id.currency_id.rate,
+				],
+				'price_unit_currency': round(line.price_unit * (line.invoice_id.company_id.currency_id.rate / line.invoice_id.currency_id.rate),decimal_precision),
+				'price_subtotal_currency': round(line.price_subtotal * (line.invoice_id.company_id.currency_id.rate / line.invoice_id.currency_id.rate),decimal_precision),
+				'tax_currency': round((line.price_unit * (line.invoice_id.company_id.currency_id.rate / line.invoice_id.currency_id.rate) * line.quantity) - line.price_subtotal * (line.invoice_id.company_id.currency_id.rate / line.invoice_id.currency_id.rate),decimal_precision),
+				'amount_currency': round((line.quantity * line.price_unit) * (line.invoice_id.company_id.currency_id.rate / line.invoice_id.currency_id.rate),decimal_precision),
+			})
+
+		return values
+
+class AccountVoucher(models.Model):
+	_inherit = 'account.voucher'
+
+	############################################################
+	#	ACCONT VOUCHER
+	############################################################
+
+	@api.model
+	def getAccountVoucher(self,domain):
+		AccountVoucher = self.env['account.voucher'].search(domain)
+		values = []
+		for voucher in AccountVoucher:
+			values.append({
+				'id': voucher.id,
+				'number':voucher.number,
+				'create_uid': voucher.create_uid.name,
+				'journal_id': [
+					voucher.journal_id.id,
+					voucher.journal_id.name,
+				],
+				'amount': voucher.amount,
+				'currency_id': [
+					voucher.currency_id.id,
+					voucher.currency_id.name,
+				],
+				'reference': voucher.reference,
+				'date': voucher.date,
+				'amount': voucher.amount,
+				'amount_currency': voucher.amount * (voucher.company_id.currency_id.rate / voucher.currency_id.rate),
+			})
+
+		return values
+
+class AccountMoveLine(models.Model):
+	_inherit = 'account.move.line'
+
+	@api.model
+	def getAccountMoveLine(self,domain):
+		AccountMoveLine = self.env['account.move.line'].search(domain)
+		decimal_precision = self.env['decimal.precision'].precision_get('Account')
+		values = []
+		for line in AccountMoveLine:
+
+			values.append({
+				'id': line.id,
+				'name': line.name,
+				'date': line.date,
+				'date_maturity': line.date_maturity,
+				'reconcile_ref': line.reconcile_ref,
+				'amount_residual': line.amount_residual,
+				'partner_id': [
+					line.partner_id.id,
+					line.partner_id.name,
+				],
+				'move_id': [
+					line.move_id.id,
+					line.move_id.name,
+				],
+				'debit': line.credit,
+				'credit': line.debit,
+			})
+
+		return values
+
+class AccounPaymentTerm(models.Model):
+	_inherit = 'account.payment.term'
+
+	check_credit = fields.Boolean("Es crédito?", default=True)

binární
models.pyc


binární
static/description/icon.png


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

@@ -0,0 +1,45 @@
+openerp.eiru_reports_crm= function (instance) {
+    "use strict";
+
+    var reporting = instance.eiru_reports_crm;
+
+    reporting_base(instance,reporting);
+
+    try {
+        /*
+        ================================
+            CRM
+        ================================
+        */
+        report_crm(reporting);
+        report_crm_task(reporting);
+        report_crm_claim(reporting);
+
+    } catch (e) {
+        // ignorar error
+    }
+
+    /*
+    ================================================================================
+        HISTORICO DE CRM
+    ================================================================================
+     */
+    instance.web.client_actions.add('eiru_reports_crm.crm_action', 'instance.eiru_reports_crm.ReportCrmWidget');
+
+    /*
+    ================================================================================
+        HISTORICO DE CRM TASK
+    ================================================================================
+     */
+    instance.web.client_actions.add('eiru_reports_crm.crm_task_action', 'instance.eiru_reports_crm.ReportCrmTaskWidget');
+
+    /*
+    ================================================================================
+        HISTORICO DE CRM RECLAMOS
+    ================================================================================
+     */
+    instance.web.client_actions.add('eiru_reports_crm.crm_claim_action', 'instance.eiru_reports_crm.ReportCrmClaimWidget');
+
+
+
+}

+ 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;
+        }
+    });
+}

+ 513 - 0
static/src/js/reports/report_crm.js

@@ -0,0 +1,513 @@
+function report_crm(reporting){
+    "use strict";
+
+    var model = openerp;
+
+    reporting.ReportCrmWidget = reporting.Base.extend({
+        template:'ReportCrm',
+        AccountVoucher: [],
+        content:[],
+        rowsData :[],
+        modules: ['crm'],
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+            'click #generate' : 'fetchGenerate',
+            '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.fetchInitial();
+        },
+
+        // 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
+        },
+
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+
+        clickAnalysisDetail: function(e, row, $element, field){
+            if (field == 'description'){
+                this.do_action({
+                    name:"CRM",
+                    type: 'ir.actions.act_window',
+                    res_model: "crm.lead",
+                    views: [[false,'form']],
+                    target: 'new',
+                    domain: [['id','=', row.id]],
+                    context: {},
+                    flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id: row.id,
+                });
+            }
+            if (field === 'partner'){
+                this.do_action({
+                    name:"Registro",
+                    type: 'ir.actions.act_window',
+                    res_model: "res.partner",
+                    views: [[false,'form']],
+                    target: 'new',
+                    domain: [['id','=', row.partner_id]],
+                    context: {},
+                    flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id: row.partner_id,
+                });
+            }
+
+             e.stopImmediatePropagation();
+        },
+
+        fetchInitial: function () {
+            var self = this;
+            self.fecthIrModuleModule().then(function (IrModuleModule) {
+                return IrModuleModule;
+            }).then(function(IrModuleModule) {
+                self.IrModuleModule = IrModuleModule;
+                return self.fetchResUser();
+            }).then(function (ResUser) {
+                self.ResUser = ResUser;
+                if(ResUser.length > 1){
+                    self.$el.find('#current-user').append('<option value="9999999">Todos los usuarios</option>');
+                    _.each(ResUser,function(item){
+                        self.$el.find('#current-user').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.user').css('display','none');
+                }
+                self.fecthCheckType();
+                return self.fetchResCompany();
+            }).then(function(ResCompany){
+                self.ResCompany = ResCompany;
+                if(ResCompany.length > 1){
+                    self.$el.find('#current-company').append('<option value="9999999">Todas las empresas</option>');
+                    _.each(ResCompany,function(item){
+                        self.$el.find('#current-company').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.company').css('display','none');
+                }
+                return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner = ResPartner;
+            });
+            self.$el.find('#generate').css('display','inline');
+            return;
+        },
+
+        fetchGenerate: function () {
+            var self = this;
+            self.$el.find('.search-form').block({
+                message: null,
+                overlayCSS: {
+                    backgroundColor: '#FAFAFA'
+                }
+            });
+            self.$el.find('.report-form').block({
+                message: null,
+                overlayCSS: {
+                    backgroundColor: '#FAFAFA'
+                }
+            });
+
+            this.fetchCrm().then(function(ResCrm) {
+                return ResCrm;
+            }).then(function (ResCrm) {
+                self.ResCrm = ResCrm;
+                return self.fetchCrmStage();
+            }).then(function(CrmStage){
+                self.CrmStage = CrmStage;
+                if(CrmStage.length > 1){
+                    self.$el.find('#current-state').append('<option value="9999999">Todas las etapas</option>');
+                    _.each(CrmStage,function(item){
+                        self.$el.find('#current-state').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.state').css('display','none');
+                }
+                return self.BuildTable();
+            });
+        },
+
+        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;
+            }
+        },
+
+        fecthIrModuleModule: function(){
+             var self = this;
+             var defer = $.Deferred();
+             var fields = ['name','id'];
+             var domain=[['state','=','installed'],['name','in',self.modules]];
+             var IrModuleModule = new model.web.Model('ir.module.module');
+             IrModuleModule.query(fields).filter(domain).all().then(function(results){
+                 defer.resolve(results);
+             })
+             return defer;
+        },
+
+         /*=====================================================================
+             Check type
+         =====================================================================*/
+         fecthCheckType: function(){
+             var self = this;
+             var modules = self.checkModel('crm');
+             if(modules.length == 0){
+                 self.$el.find('.type').css('display','none');
+             }
+         },
+
+         /*=====================================================================
+             USER
+         =====================================================================*/
+         fetchResUser: function() {
+             var self = this;
+             var defer = $.Deferred();
+             var fields = ['id','name','store_id'];
+             var ResUser = new model.web.Model('res.users');
+             ResUser.query(fields).filter().all().then(function (results) {
+                 defer.resolve(results);
+             });
+             return defer;
+         },
+
+         /*====================================================================
+             RES COMPANY
+         ====================================================================*/
+         fetchResCompany: function(){
+             var self = this;
+             var defer = $.Deferred();
+             var currency = new model.web.Model('res.company');
+             var field=['id','name','currency_id','logo'];
+             currency.query(field).filter().all().then(function(results){
+                 defer.resolve(results);
+             });
+             return defer;
+         },
+
+
+        /*====================================================================
+            CRM
+        ====================================================================*/
+        fetchCrm: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var stage_ids = _.flatten(_.map(self.CrmStage, function (item) {
+                return item.id;
+            }));
+            var state = self.$el.find('#current-state').val();
+            var company = self.$el.find('#current-company').val();
+            var user = self.$el.find('#current-user').val();
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+            var domain = [['type','=','opportunity'],['active', '=', true]];
+            if(state && state != 9999999){
+                domain.push(['stage_id','=',parseInt(state)]);
+            }
+            if(company && company != 9999999){
+                domain.push(['company_id','=',parseInt(company)]);
+            }
+            if(user && user != 9999999){
+                domain.push(['user_id','=',parseInt(user)]);
+            }
+            if(desde){
+                var date = desde.split('/')
+                date = (date[2]+"-"+date[1]+"-"+date[0])
+                domain.push(['create_date','>',date]);
+            }
+            if(hasta){
+                var date = hasta.split('/')
+                date = (date[2]+"-"+date[1]+"-"+date[0])
+                domain.push(['create_date','<',date]);
+            }
+            var fields = [
+                'id',
+                'company_id',
+                'partner_id',
+                'name',
+                'description',
+                'create_date',
+                'user_id',
+                'stage_id',
+                'date_last_stage_update',
+                'write_date',
+                'type',
+            ];
+            var ResCrm = new model.web.Model('crm.lead');
+            ResCrm.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        fetchCrmStage: function () {
+            var self = this;
+            var defer = $.Deferred();
+
+            var filter = [['type', 'in',['both','opportunity']]];
+            var CrmStage = new model.web.Model('crm.case.stage');
+            CrmStage.query(['id', 'name', 'type']).filter(filter).all().then(function(results){
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+
+        fetchResPartner: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var ResPartner = new model.web.Model('res.partner');
+            ResPartner.query(['id','name','ruc']).filter([['active', '=', true]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        search: function () {
+            var self = this;
+            var results = self.ResPartner;
+            results = _.map(results, function (item) {
+                return {
+                        label: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc),
+                        value: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc)
+                }
+            });
+            self.$('#partner').autocomplete({
+                source: results,
+                minLength:0,
+                search: function(event, ui) {
+                    if (!(self.$('#partner').val())){
+                        self.factSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.factSearch();
+                },
+                select: function(event, ui) {
+                    self.factSearch();
+                }
+            });
+        },
+
+        /*====================================================================
+            BUILD
+        ====================================================================*/
+        BuildTable: function(){
+            var self = this;
+            var data = [];
+            var company = $('#current-company').val();
+            if(company && company != 9999999){
+                var ResCompany = self.getResCompany(company).shift();
+
+            }else{
+                // var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
+            }
+            var ResCrm = self.ResCrm;
+            _.each(ResCrm, function(item){
+                data.push({
+                    id: item.id,
+                    name : self.valorNull(item.name),
+                    description: self.valorNull(item.description),
+                    partner: item.partner_id[1],
+                    create_date: moment(item.create_date).format("DD/MM/YYYY"),
+                    date_last_stage_update: moment(item.date_last_stage_update).format("DD/MM/YYYY"),
+                    write_date: moment(item.write_date).format("DD/MM/YYYY"),
+                    date: moment(item.create_date).format("YYYY-MM-DD"),
+                    user: item.user_id[1],
+                    stage_id: item.stage_id[0],
+                    stage: item.stage_id[1],
+                    partner_id : item.partner_id[0],
+                });
+            });
+            self.content = data;
+            self.loadTable(data);
+            self.$el.find('.report-form').css('display','block');
+            self.$el.find('.search-form').unblock();
+            self.$el.find('.report-form').unblock();
+        },
+
+        loadTable:function(rowsTable){
+            var self = this;
+            self.rowsData = rowsTable;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load',rowsTable);
+        },
+
+        clickOnAction: function (e) {
+            var self = this;
+            var ResCompany;
+            var action = this.$el.find(e.target).val();
+            var company = $('#current-company').val();
+            if(company && company != 9999999){
+                ResCompany = self.getResCompany(company).shift();
+            //    var CurrencyBase = self.getResCurrency(ResCompany.currency_id[0]).shift();
+            }else{
+                ResCompany = self.ResCompany[0];
+            //    var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
+            }
+            var getColumns=[];
+            var rows=[];
+            var table = this.$el.find("#table");
+            var column = table.bootstrapTable('getVisibleColumns');
+            var row = table.bootstrapTable('getData');
+            if (action === 'pdf') {
+                var data = _.map(column, function (val){return val.field});
+                _.each(row,function (item){
+                    rows.push(_.pick(item, data));
+                });
+                _.each(_.map(column,function(val){
+                    return val}), function(item){
+                    getColumns.push([{
+                        title: item.title,
+                        dataKey: item.field
+                    }]);
+                });
+                this.drawPDF(_.flatten(getColumns),row,ResCompany)
+            }
+        },
+
+        drawPDF: function (getColumns,row,ResCompany) {
+            var self = this;
+            // var base64Img = 'data:,' + ResCompany.logo;
+            var hoy = moment().format('DD/MM/YYYY');
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new jsPDF();
+
+            pdfDoc.autoTable(getColumns, row, {
+                showHeader: 'firstPage',
+                theme: 'grid',
+                styles: {
+                    overflow: 'linebreak',
+                    fontSize: 7,
+                    columnWidth: 'wrap',
+                },
+                headerStyles: {
+                    fillColor: [76, 133, 248],
+                    fontSize: 8
+                },
+
+                columnStyles: {
+                  name : {columnWidth: 25},
+                  description : {columnWidth: 65},
+                  partner : {columnWidth: 25},
+                  date : {columnWidth: 18},
+                  stage : {columnWidth: 20},
+                  date_last_stage_update: {columnWidth: 18, halign:'center'},
+                  write_date: {columnWidth: 18, halign:'center'},
+                  user : {columnWidth: 20},
+                },
+                margin: { top: 20, horizontal: 7},
+
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Histórico de CRM', data.settings.margin.left, 10);
+
+
+                    pdfDoc.setFontSize(9);
+                    pdfDoc.setFontStyle('normal');
+                    pdfDoc.setTextColor(40)
+                    // pdfDoc.text(6,14,tipo);
+
+                    // 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(175,pdfDoc.internal.pageSize.height - 5,str);
+                }
+            });
+
+            if (typeof pdfDoc.putTotalPages === 'function') {
+                pdfDoc.putTotalPages(totalPagesExp);
+            }
+            row.pop();
+            pdfDoc.save('Histórico de CRM.pdf')
+        },
+    });
+}

+ 454 - 0
static/src/js/reports/report_crm_claim.js

@@ -0,0 +1,454 @@
+function report_crm_claim(reporting){
+    "use strict";
+
+    var model = openerp;
+
+    reporting.ReportCrmClaimWidget = reporting.Base.extend({
+        template:'ReportCrmClaim',
+        content:[],
+        rowsData :[],
+        modules:['crm','eiru_crm'],
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+
+            'click #generate' : 'fetchGenerate',
+            '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.fetchInitial();
+        },
+
+
+        // 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
+        },
+
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+
+        clickAnalysisDetail: function(e, row, $element, field){
+            if (field == 'partner'){
+                 this.do_action({
+                     name:"Registro de Cliente",
+                     type: 'ir.actions.act_window',
+                     res_model: "res.partner",
+                     views: [[false,'form']],
+                     target: 'new',
+                     domain: [['id','=', row.partner_id]],
+                     context: {},
+                     flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                     res_id: row.partner_id,
+                 });
+            }
+            if (field == 'description'){
+                this.do_action({
+                    name:"Registro de Reclamos",
+                    type: 'ir.actions.act_window',
+                    res_model: "crm.claim",
+                    views: [[false,'form']],
+                    target: 'new',
+                    domain: [['id','=', row.id]],
+                    context: {},
+                    flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id: row.id,
+                });
+            }
+
+             e.stopImmediatePropagation();
+        },
+
+        fetchInitial: function () {
+            var self = this;
+            self.fecthIrModuleModule().then(function (IrModuleModule) {
+                return IrModuleModule;
+            }).then(function(IrModuleModule) {
+                self.IrModuleModule = IrModuleModule;
+                return self.fetchResUser();
+            }).then(function (ResUser) {
+                self.ResUser = ResUser;
+                if(ResUser.length > 1){
+                    self.$el.find('#current-user').append('<option value="9999999">Todos los usuarios</option>');
+                    _.each(ResUser,function(item){
+                        self.$el.find('#current-user').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.user').css('display','none');
+                }
+                self.fecthCheckType();
+                return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner = ResPartner;
+            });
+            self.$el.find('#generate').css('display','inline');
+            return;
+        },
+
+        fetchGenerate: function () {
+            var self = this;
+            self.$el.find('.search-form').block({
+                message: null,
+                overlayCSS: {
+                    backgroundColor: '#FAFAFA'
+                }
+            });
+            self.$el.find('.report-form').block({
+                message: null,
+                overlayCSS: {
+                    backgroundColor: '#FAFAFA'
+                }
+            });
+
+            this.fetchCrmClaim().then(function(ResCrmClaim) {
+                return ResCrmClaim;
+            }).then(function (ResCrmClaim) {
+                self.ResCrmClaim = ResCrmClaim;
+                return self.fetchCrmClaimStage();
+            }).then(function (CrmClaimStage) {
+                self.CrmClaimStage = CrmClaimStage;
+                return self.BuildTable();
+            });
+        },
+
+        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;
+            }
+        },
+
+        fecthIrModuleModule: function(){
+             var self = this;
+             var defer = $.Deferred();
+             var fields = ['name','id'];
+             var domain=[['state','=','installed'],['name','in',self.modules]];
+             var IrModuleModule = new model.web.Model('ir.module.module');
+             IrModuleModule.query(fields).filter(domain).all().then(function(results){
+                 defer.resolve(results);
+             })
+             return defer;
+        },
+
+         /*=====================================================================
+             Check type
+         =====================================================================*/
+         fecthCheckType: function(){
+             var self = this;
+             var modules = self.checkModel('eiru_crm');
+             if(modules.length == 0){
+                 self.$el.find('.type').css('display','none');
+             }
+        },
+
+         /*=====================================================================
+             USER
+         =====================================================================*/
+         fetchResUser: function() {
+             var self = this;
+             var defer = $.Deferred();
+             var fields = ['id','name','store_id'];
+             var ResUser = new model.web.Model('res.users');
+             ResUser.query(fields).filter().all().then(function (results) {
+                 defer.resolve(results);
+             });
+             return defer;
+         },
+
+         /*====================================================================
+             CRM CLAIM
+         ====================================================================*/
+         fetchCrmClaim: function() {
+             var self = this;
+             var defer = $.Deferred();
+             var stage_ids = _.flatten(_.map(self.CrmClaimStage, function (item) {
+                 return item.id;
+             }));
+             var state = self.$el.find('#current-state').val();
+             var desde = self.$el.find('#from').val();
+             var hasta = self.$el.find('#to').val();
+             var domain = [['active', '=', true]];
+             // if(state != 9999999){
+             //     domain.push(['stage_id','=',state]);
+             // }
+             if(desde){
+                 var date = desde.split('/')
+                 date = (date[2]+"-"+date[1]+"-"+date[0])
+                 domain.push(['date','>',date]);
+             }
+             if(hasta){
+                 var date = hasta.split('/')
+                 date = (date[2]+"-"+date[1]+"-"+date[0])
+                 domain.push(['date','<',date]);
+             }
+             var fields = [
+                 'id',
+                 'partner_id',
+                 'name',
+                 'description',
+                 'date',
+                 'user_id',
+                 'cause',
+                 'date_deadline',
+                 'stage_id',
+                 'active',
+             ];
+             var ResCrmClaim = new model.web.Model('crm.claim');
+             ResCrmClaim.query(fields).filter(domain).all().then(function (results) {
+                 defer.resolve(results);
+             });
+             return defer;
+        },
+
+        fetchCrmClaimStage: function () {
+            var self = this;
+            var defer = $.Deferred();
+
+            var CrmClaimStage = new model.web.Model('crm.claim.stage');
+            CrmClaimStage.query(['id', 'name', 'description']).filter().all().then(function(results){
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+
+        fetchResPartner: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var ResPartner = new model.web.Model('res.partner');
+            ResPartner.query(['id','name','ruc']).filter([['active', '=', true]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        // getCrmClaim: function (id) {
+        //     var self = this;
+        //     return _.filter(self.ResCrmClaim,function (item) {
+        //         return item.opportunity_id == id;
+        //     });
+        // },
+
+        getCrmClaimStage: function (id) {
+            var self = this;
+            return _.filter(self.CrmClaimStage,function (item) {
+                return item.id == id;
+            });
+        },
+
+        BuildTable: function(){
+            var self = this;
+            var data = [];
+            var stageclaim;
+            var stage;
+            var state_id;
+            var state;
+            var crmclaim = self.ResCrmClaim;
+
+            _.each(crmclaim, function(item){
+
+
+                // stageclaim = self.getCrmClaimStage(item.id);
+
+                // if(!stageclaim){
+                //     state_id="";
+                //     state="";
+                //
+                // }else{
+                //     state_id=stageclaim.id;
+                //     state=stageclaim.name;
+                // }
+                    data.push({
+                        id : item.id,
+                        partner: self.valorNull(item.partner_id[1]),
+                        description: self.valorNull(item.description),
+                        name: self.valorNull(item.name),
+                        create_date: moment(item.date).format("DD/MM/YYYY H:MM"),
+                        date: moment(item.date).format("YYYY-MM-DD"),
+                        user: item.user_id[1],
+                        cause:  item.cause,
+                        stage_name: item.stage_id[1],
+                        stage: item.stage_id[0],
+                        partner_id : item.partner_id[0],
+                    });
+            });
+            self.content = data;
+            self.loadTable(data);
+            self.$el.find('.report-form').css('display','block');
+            self.$el.find('.search-form').unblock();
+            self.$el.find('.report-form').unblock();
+        },
+
+        loadTable:function(rowsTable){
+            var self = this;
+            self.rowsData = rowsTable;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load',rowsTable);
+        },
+
+        clickOnAction: function (e) {
+            var self = this;
+            var action = self.$el.find(e.target).val();
+            var getColumns=[];
+            var rows=[];
+            var table = self.$el.find("#table");
+            var column = table.bootstrapTable('getVisibleColumns');
+            var row = table.bootstrapTable('getData');
+            if (action === 'pdf') {
+                 var data = _.map(column, function (val){return val.field});
+                 _.each(row,function (item){
+                     rows.push(_.pick(item, data));
+                 });
+                 // Obtener los nombre de la Cabecera
+                 _.each(_.map(column,function(val){
+                        return val}), function(item){
+                        getColumns.push([{
+                            title: item.title,
+                            dataKey: item.field
+                        }]);
+                 });
+                 this.drawPDF(_.flatten(getColumns),rows)
+             }
+        },
+
+        drawPDF: function (getColumns,row) {
+            var self = this;
+            var hoy = moment().format('DD/MM/YYYY');
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new jsPDF();
+
+            pdfDoc.autoTable(getColumns, row, {
+                showHeader: 'firstPage',
+                theme: 'grid',
+                styles: {
+                    overflow: 'linebreak',
+                    fontSize: 7,
+                    columnWidth: 'wrap',
+                },
+                headerStyles: {
+                    fillColor: [76, 133, 248],
+                    fontSize: 8
+                },
+
+                columnStyles: {
+                  create_date : {columnWidth: '8px'},
+                  partner : {columnWidth: '8px'},
+                  activity : {columnWidth: '8px'},
+                  user : {columnWidth: '8px'},
+                  description : {columnWidth: '8px'},
+                  stage_name : {columnWidth: '8px'},
+                },
+                margin: { top: 20, horizontal: 7},
+
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Histórico de Reclamos', data.settings.margin.left, 10);
+
+
+                    pdfDoc.setFontSize(9);
+                    pdfDoc.setFontStyle('normal');
+                    pdfDoc.setTextColor(40)
+                    // pdfDoc.text(6,14,tipo);
+
+                    // 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(175,pdfDoc.internal.pageSize.height - 5,str);
+                }
+            });
+
+
+            if (typeof pdfDoc.putTotalPages === 'function') {
+                pdfDoc.putTotalPages(totalPagesExp);
+            }
+            row.pop();
+            pdfDoc.save('Histórico de Reclamos.pdf')
+        },
+    });
+}

+ 482 - 0
static/src/js/reports/report_crm_task.js

@@ -0,0 +1,482 @@
+function report_crm_task(reporting){
+    "use strict";
+
+    var model = openerp;
+
+    reporting.ReportCrmTaskWidget = reporting.Base.extend({
+        template:'ReportCrmTask',
+        content:[],
+        rowsData :[],
+        modules:['crm','eiru_crm'],
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+
+            'click #generate' : 'fetchGenerate',
+            '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.fetchInitial();
+        },
+
+
+        // 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
+        },
+
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+
+        clickAnalysisDetail: function(e, row, $element, field){
+            if (field == 'partner'){
+                 this.do_action({
+                     name:"Registro de Cliente",
+                     type: 'ir.actions.act_window',
+                     res_model: "res.partner",
+                     views: [[false,'form']],
+                     target: 'new',
+                     domain: [['id','=', row.partner_id]],
+                     context: {},
+                     flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                     res_id: row.partner_id,
+                 });
+            }
+            if (field === 'activity'){
+                this.do_action({
+                    name:"Registro de Tareas",
+                    type: 'ir.actions.act_window',
+                    res_model: "crm.task",
+                    views: [[false,'form']],
+                    target: 'new',
+                    domain: [['id','=', row.id]],
+                    context: {},
+                    flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id: row.id,
+                });
+            }
+
+             e.stopImmediatePropagation();
+        },
+
+        fetchInitial: function () {
+            var self = this;
+            self.fecthIrModuleModule().then(function (IrModuleModule) {
+                return IrModuleModule;
+            }).then(function(IrModuleModule) {
+                self.IrModuleModule = IrModuleModule;
+                return self.fetchResUser();
+            }).then(function (ResUser) {
+                self.ResUser = ResUser;
+                if(ResUser.length > 1){
+                    self.$el.find('#current-user').append('<option value="9999999">Todos los usuarios</option>');
+                    _.each(ResUser,function(item){
+                        self.$el.find('#current-user').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.user').css('display','none');
+                }
+                self.fecthCheckType();
+                return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner = ResPartner;
+            });
+            self.$el.find('#generate').css('display','inline');
+            return;
+        },
+
+        fetchGenerate: function () {
+            var self = this;
+            self.$el.find('.search-form').block({
+                message: null,
+                overlayCSS: {
+                    backgroundColor: '#FAFAFA'
+                }
+            });
+            self.$el.find('.report-form').block({
+                message: null,
+                overlayCSS: {
+                    backgroundColor: '#FAFAFA'
+                }
+            });
+
+            this.fetchCrmTask().then(function(ResCrmTask) {
+                return ResCrmTask;
+            }).then(function (ResCrmTask) {
+                self.ResCrmTask = ResCrmTask;
+                return self.fetchTaskType();
+            }).then(function (TaskType) {
+                self.TaskType = TaskType;
+                if(TaskType.length > 1){
+                    self.$el.find('#current-type').append('<option value="9999999">Todos los medios</option>');
+                    _.each(TaskType,function(item){
+                        self.$el.find('#current-type').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.currenttype').css('display','none');
+                }
+                return self.fetchCrm();
+            }).then(function (ResCrm) {
+                self.ResCrm = ResCrm;
+                return self.BuildTable();
+            });
+        },
+
+        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;
+            }
+        },
+
+        fecthIrModuleModule: function(){
+             var self = this;
+             var defer = $.Deferred();
+             var fields = ['name','id'];
+             var domain=[['state','=','installed'],['name','in',self.modules]];
+             var IrModuleModule = new model.web.Model('ir.module.module');
+             IrModuleModule.query(fields).filter(domain).all().then(function(results){
+                 defer.resolve(results);
+             })
+             return defer;
+        },
+
+         /*=====================================================================
+             Check type
+         =====================================================================*/
+         fecthCheckType: function(){
+             var self = this;
+             var modules = self.checkModel('eiru_crm');
+             if(modules.length == 0){
+                 self.$el.find('.type').css('display','none');
+             }
+        },
+
+         /*=====================================================================
+             USER
+         =====================================================================*/
+         fetchResUser: function() {
+             var self = this;
+             var defer = $.Deferred();
+             var fields = ['id','name','store_id'];
+             var ResUser = new model.web.Model('res.users');
+             ResUser.query(fields).filter().all().then(function (results) {
+                 defer.resolve(results);
+             });
+             return defer;
+         },
+
+         /*====================================================================
+             CRM TASK
+         ====================================================================*/
+         fetchCrmTask: function() {
+             var self = this;
+             var defer = $.Deferred();
+             var stage_ids = _.flatten(_.map(self.TaskType, function (item) {
+                 return item.id;
+             }));
+             var state = self.$el.find('#current-state').val();
+             var currenttype = self.$el.find('#current-type').val();
+             var desde = self.$el.find('#from').val();
+             var hasta = self.$el.find('#to').val();
+             var domain = [['active', '=', true]];
+             if(state != 9999999){
+                 domain.push(['state','=',state]);
+             }
+             if(currenttype && currenttype != 9999999){
+                 domain.push(['task_type_id','=',parseInt(currenttype)]);
+             }
+             if(desde){
+                 var date = desde.split('/')
+                 date = (date[2]+"-"+date[1]+"-"+date[0])
+                 domain.push(['create_date','>',date]);
+             }
+             if(hasta){
+                 var date = hasta.split('/')
+                 date = (date[2]+"-"+date[1]+"-"+date[0])
+                 domain.push(['create_date','<',date]);
+             }
+             var fields = [
+                 'id',
+                 'partner_id',
+                 'name',
+                 'description',
+                 'create_date',
+                 'user_id',
+                 'task_type_id',
+                 'opportunity_id',
+                 'state',
+                 'date_action_next',
+             ];
+             var ResCrmTask = new model.web.Model('crm.task');
+             ResCrmTask.query(fields).filter(domain).all().then(function (results) {
+                 defer.resolve(results);
+             });
+             return defer;
+        },
+
+        fetchTaskType: function () {
+            var self = this;
+            var defer = $.Deferred();
+
+            var TaskType = new model.web.Model('crm.task.type');
+            TaskType.query(['id', 'name']).filter([['active', '=', true]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        fetchCrm: function () {
+            var self = this;
+            var defer = $.Deferred();
+
+            var ResCrm = new model.web.Model('crm.lead');
+            ResCrm.query(['id', 'partner_id', 'name', 'description', 'create_date', 'user_id', 'stage_id', 'type']).filter([['active', '=', true]]).all().then(function(results){
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+
+        fetchResPartner: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var ResPartner = new model.web.Model('res.partner');
+            ResPartner.query(['id','name','ruc']).filter([['active', '=', true]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        getCrm: function (id) {
+            var self = this;
+            return _.filter(self.ResCrm,function (item) {
+                return item.opportunity_id == id;
+            });
+        },
+
+        getCrmTask: function (id) {
+            var self = this;
+            return _.filter(self.ResCrmTask,function (item) {
+                return item.id == id;
+            });
+        },
+
+        BuildTable: function(){
+            var self = this;
+            var data = [];
+            var Crm;
+            var taskType;
+            var stage;
+            var crmtask = self.ResCrmTask;
+            _.each(crmtask, function(item){
+
+                if(item.state=='pending'){
+                    stage = 'Pendiente'
+                }else{
+                    if(item.state=='done'){
+                        stage = 'Realizado'
+                    }else{
+                        stage = 'Cancelado'
+                    }
+                }
+
+                // taskType = self.getCrmTask(item.id).shift();
+                // Crm = self.getCrm(item.id);
+
+                data.push({
+                    id : item.id,
+                    opportunity_id : self.valorNull(item.opportunity_id),
+                    partner: self.valorNull(item.partner_id[1]),
+                    description: self.valorNull(item.description),
+                    activity: self.valorNull(item.name),
+                    create_date: moment(item.create_date).format("DD/MM/YYYY"),
+                    date: moment(item.create_date).format("YYYY-MM-DD"),
+                    user: item.user_id[1],
+                    task_type_id: item.task_type_id[0],
+                    next_date: moment(item.date_action_next).format("DD/MM/YYYY"),
+                    task_name:  item.task_type_id[1],
+                    stage: stage,
+                    partner_id : item.partner_id[0],
+                });
+            });
+            self.content = data;
+            self.loadTable(data);
+            self.$el.find('.report-form').css('display','block');
+            self.$el.find('.search-form').unblock();
+            self.$el.find('.report-form').unblock();
+        },
+
+        loadTable:function(rowsTable){
+            var self = this;
+            self.rowsData = rowsTable;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load',rowsTable);
+        },
+
+        clickOnAction: function (e) {
+            var self = this;
+            var action = self.$el.find(e.target).val();
+            var getColumns=[];
+            var rows=[];
+            var table = self.$el.find("#table");
+            var column = table.bootstrapTable('getVisibleColumns');
+            var row = table.bootstrapTable('getData');
+            if (action === 'pdf') {
+                 var data = _.map(column, function (val){return val.field});
+                 _.each(row,function (item){
+                     rows.push(_.pick(item, data));
+                 });
+                 // Obtener los nombre de la Cabecera
+                 _.each(_.map(column,function(val){
+                        return val}), function(item){
+                        getColumns.push([{
+                            title: item.title,
+                            dataKey: item.field
+                        }]);
+                 });
+                 this.drawPDF(_.flatten(getColumns),rows)
+             }
+        },
+
+        drawPDF: function (getColumns,row) {
+            var self = this;
+            var hoy = moment().format('DD/MM/YYYY');
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new jsPDF();
+
+            pdfDoc.autoTable(getColumns, row, {
+                showHeader: 'firstPage',
+                theme: 'grid',
+                styles: {
+                    overflow: 'linebreak',
+                    fontSize: 7,
+                    columnWidth: 'wrap',
+                },
+                headerStyles: {
+                    fillColor: [76, 133, 248],
+                    fontSize: 8
+                },
+
+                columnStyles: {
+                  create_date : {columnWidth: '8px'},
+                  partner : {columnWidth: '8px'},
+                  activity : {columnWidth: '8px'},
+                  user : {columnWidth: '8px'},
+                  description : {columnWidth: '8px'},
+                  task_name: {columnWidth: '8px'},
+                  stage : {columnWidth: '8px'},
+                },
+                margin: { top: 20, horizontal: 7},
+
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Histórico de Tareas CRM', data.settings.margin.left, 10);
+
+
+                    pdfDoc.setFontSize(9);
+                    pdfDoc.setFontStyle('normal');
+                    pdfDoc.setTextColor(40)
+                    // pdfDoc.text(6,14,tipo);
+
+                    // 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(175,pdfDoc.internal.pageSize.height - 5,str);
+                }
+            });
+
+            if (typeof pdfDoc.putTotalPages === 'function') {
+                pdfDoc.putTotalPages(totalPagesExp);
+            }
+            row.pop();
+            pdfDoc.save('Histórico de Tareas CRM.pdf')
+        },
+    });
+}

+ 91 - 0
static/src/reports/informe_crm_reclamos.xml

@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+<data>
+
+         <report id="informe_crm_reclamos"
+            model="crm.claim"
+            string="Listado de Reclamos de Clientes"
+            report_type="qweb-pdf"
+            name="informes_crm_reclamos.report_claim2"
+            file="informes_crm_reclamos.report_claim2"
+         />
+
+  <template id="report_claim2">
+    <t t-call="report.html_container">
+          <t t-call="report.external_layout">
+            <div class="page">
+				<style type="text/css">
+						.crm_tcab{
+                            font-size: 3mm;
+                            font-family: Arial, Helvetica, sans-serif;
+                        }
+
+                        .crmc_tbody{
+                            font-size: 2.8mm;
+                            font-family: Arial, Helvetica, sans-serif;
+                        }
+                        .taxtotal{
+                            font-size: 2.8mm;
+                        }
+						.total{
+                            font-size: 2.8mm;
+                        }
+						.untotal{
+                            font-size: 2.8mm;
+                        }
+						.logo1{
+                            width: 100%;
+                            top: 1.5cm;
+                        }
+
+				</style>
+			   <h4 class="text-center">Listado de Reclamos de Clientes</h4>
+               <div class="logo1"> </div>
+			   <table class="table table-bordered">
+					<thead class="crm_tcab">
+						<tr class="active">
+							<th class="text-center">Fecha y Hora</th>
+							<th class="text-center">Cliente</th>
+							<th class="text-center">Motivo del Reclamo</th>
+							<th class="text-center">Descripcion y Acciones</th>
+							<th class="text-center">Causa</th>
+							<th class="text-center">Responsable</th>
+							<th class="text-center">Fecha Limite</th>
+							<th class="text-center">Estado</th>
+						</tr>
+					</thead>
+               <t t-foreach="docs" t-as="o">
+                <tbody class="crmc_tbody">
+                          <td class="text-left">
+                                <span t-field="o.date"/>
+                          </td>
+                          <td class="text-left">
+                                <span t-field="o.partner_id"/>
+                          </td>
+                          <td class="text-left">
+                                <span t-field="o.name"/>
+                          </td>
+                          <td class="text-left">
+                                <span t-field="o.description"/>
+                          </td>
+                           <td class="text-left">
+                                <span t-field="o.cause"/>
+                          </td>
+                          <td class="text-left">
+                                <span t-field="o.user_id"/>
+                          </td>
+                          <td class="text-left">
+                                <span t-field="o.date_deadline"/>
+                          </td>
+						  <td class="text-left">
+                                <span t-field="o.stage_id"/>
+                          </td>
+                </tbody>
+               </t>
+             </table>
+            </div>
+          </t>
+    </t>
+  </template>
+</data>
+</openerp>

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

@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportCrm">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1 class="report_title">Histórico de CRM</h1>
+            </div>
+
+            <div class="container search-form" style="border-bottom:1px solid #eee; width:90%;">
+                <div class="row">
+                    <div class="col-lg-3 company filter-style">
+                        <label>Empresa</label>
+                        <select id="current-company" class="form-control form-control-sm"></select>
+                    </div>
+                    <div class="col-lg-3 state filter-style">
+                        <label>Todas las etapas</label>
+                        <select id="current-state" class="form-control form-control-sm">
+                        </select>
+                    </div>
+                    <div class="col-lg-3 user filter-style">
+                        <label>Todos los Usuarios</label>
+                        <select id="current-user" class="form-control form-control-sm"></select>
+                    </div>
+                    <br/>
+                </div>
+                <div class="row">
+                        <div class="col-lg-3 filter-style">
+                            <div class="input-group">
+                                <span class="input-group-addon" id="basic-addon1">Desde</span>
+                                <input type="text" id="from" class="form-control" aria-describedby="basic-addon1"/>
+                            </div>
+                        </div>
+                        <div class="col-lg-3 filter-style">
+                            <div class="input-group">
+                                <span class="input-group-addon" id="basic-addon1">Hasta</span>
+                                <input type="text" id="to" class="form-control" aria-describedby="basic-addon1"/>
+                            </div>
+                        </div>
+                </div>
+                <div class="row">
+                    <div class="text-center" style="padding-top:20px;">
+                        <a id="generate" type="button" class="btn btn-danger" aria-label="Left Align" style="color:#fff;display:none;">
+                          Generar
+                        </a>
+                    </div>
+                    <br/>
+                </div>
+            </div>
+            <div class="report-form" style="display:none;">
+                <div id="toolbar">
+                    <button class="oe_button oe_form_button oe_highlight" value="pdf">PDF</button>
+                </div>
+
+                <div class="container" style="width:90%;">
+                    <div class="bootstrap-table">
+                        <div class="fixed-table-container" style="border:none;">
+                            <div class="fixed-table-body">
+                                <table id="table"
+                                    data-pagination="true"
+                                    data-toggle="table"
+                                    data-toolbar="#toolbar"
+                                    data-show-columns="true"
+                                    data-height="auto"
+                                    data-classes="table table-hover table-condensed"
+                                    data-row-style="rowStyle"
+                                    data-search="true"
+                                    data-show-export="true"
+                                    data-show-toggle="true"
+                                    data-pagination-detail-h-align="left"
+                                    data-show-footer="true"
+                                    data-footer-style="footerStyle"
+                                    data-buttons-class="oe_button oe_form_button oe_highlight"
+                                    data-show-pagination-switch="true"
+                                    >
+                                    <thead style="background:none;">
+                                        <tr>
+                                            <th data-field="name" data-sortable="true">Asunto</th>
+                                            <th data-field="description">Descripcion</th>
+                                            <th data-field="partner" data-sortable="true">Cliente</th>
+                                            <th data-field="create_date" data-sortable="true">Fecha</th>
+                                            <th data-field="stage" data-sortable="true">Etapa</th>
+                                            <th data-field="date_last_stage_update" data-sortable="true" data-align="center">Fecha Cambio Etapa</th>
+                                            <th data-field="write_date" data-sortable="true" data-align="center">Fecha Modificado</th>
+                                        </tr>
+                                    </thead>
+                                </table>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </t>
+</template>

+ 92 - 0
static/src/reports/report_crm_claim.xml

@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportCrmClaim">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1 class="report_title">Histórico de Reclamos</h1>
+            </div>
+
+            <div class="container search-form" style="border-bottom:1px solid #eee; width:90%;">
+
+                <!-- <div class="row">
+
+                    <div class="col-lg-3">
+                        <label>Estado</label>
+                        <select id="current-state" class="form-control form-control-sm">
+                            <option value="9999999">Todos los estados</option>
+                            <option value="pending">Pendiente</option>
+                            <option value="done">Realizado</option>
+                            <option value="cancel">Cancelado</option>
+                        </select>
+                    </div>
+                </div> -->
+
+                <div class="row">
+                    <div class="col-lg-3 filter-style">
+                        <div class="input-group">
+                            <span class="input-group-addon" id="basic-addon1">Desde</span>
+                            <input type="text" id="from" class="form-control" aria-describedby="basic-addon1"/>
+                        </div>
+                    </div>
+                    <div class="col-lg-3 filter-style">
+                        <div class="input-group">
+                            <span class="input-group-addon" id="basic-addon1">Hasta</span>
+                            <input type="text" id="to" class="form-control" aria-describedby="basic-addon1"/>
+                        </div>
+                    </div>
+                </div>
+                <div class="row">
+                    <div class="text-center" style="padding-top:20px;">
+                        <a id="generate" type="button" class="btn btn-danger" aria-label="Left Align" style="color:#fff;display:none;">
+                            Generar
+                        </a>
+                    </div>
+                    <br/>
+                </div>
+            </div>
+
+            <div class="report-form" style="display:none;">
+                <div id="toolbar">
+                    <button class="oe_button oe_form_button oe_highlight" value="pdf" id="pdf">PDF</button>
+                </div>
+                <div class="container" style="width:90%;">
+                    <div class="bootstrap-table">
+                        <div class="fixed-table-container" style="border:none;">
+                            <div class="fixed-table-body">
+                                <table id="table"
+                                    data-pagination="true"
+                                    data-toggle="table"
+                                    data-toolbar="#toolbar"
+                                    data-show-columns="true"
+                                    data-height="auto"
+                                    data-classes="table table-hover table-condensed"
+                                    data-row-style="rowStyle"
+                                    data-search="true"
+                                    data-show-export="true"
+                                    data-show-toggle="true"
+                                    data-pagination-detail-h-align="left"
+                                    data-show-footer="true"
+                                    data-footer-style="footerStyle"
+                                    data-buttons-class="oe_button oe_form_button oe_highlight"
+                                    data-show-pagination-switch="true"
+                                    >
+                                    <thead style="background:none;">
+                                        <tr>
+                                            <th data-field="create_date" data-sortable="true">Fecha</th>
+                                            <th data-field="partner">Cliente</th>
+                                            <th data-field="name" data-sortable="true">Motivo del Reclamo</th>
+                                            <th data-field="description">Causa</th>
+                                            <th data-field="user">Responsable</th>
+                                            <th data-field="date_deadline">Fecha Limite</th>
+                                            <th data-field="stage_name">Estado</th>
+                                        </tr>
+                                    </thead>
+                                </table>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </t>
+</template>

+ 96 - 0
static/src/reports/report_crm_task.xml

@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportCrmTask">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1 class="report_title">Histórico de Tareas CRM</h1>
+            </div>
+
+            <div class="container search-form" style="border-bottom:1px solid #eee; width:90%;">
+
+                <div class="row">
+                    <div class="col-lg-3 currenttype">
+                        <label>Todos los Medios</label>
+                        <select id="current-type" class="form-control form-control-sm">
+                        </select>
+                    </div>
+                    <div class="col-lg-3">
+                        <label>Estado</label>
+                        <select id="current-state" class="form-control form-control-sm">
+                            <option value="9999999">Todos los estados</option>
+                            <option value="pending">Pendiente</option>
+                            <option value="done">Realizado</option>
+                            <option value="cancel">Cancelado</option>
+                        </select>
+                    </div>
+                </div>
+
+                <div class="row">
+                    <div class="col-lg-3 filter-style">
+                        <div class="input-group">
+                            <span class="input-group-addon" id="basic-addon1">Desde</span>
+                            <input type="text" id="from" class="form-control" aria-describedby="basic-addon1"/>
+                        </div>
+                    </div>
+                    <div class="col-lg-3 filter-style">
+                        <div class="input-group">
+                            <span class="input-group-addon" id="basic-addon1">Hasta</span>
+                            <input type="text" id="to" class="form-control" aria-describedby="basic-addon1"/>
+                        </div>
+                    </div>
+                </div>
+                <div class="row">
+                    <div class="text-center" style="padding-top:20px;">
+                        <a id="generate" type="button" class="btn btn-danger" aria-label="Left Align" style="color:#fff;display:none;">
+                            Generar
+                        </a>
+                    </div>
+                    <br/>
+                </div>
+            </div>
+
+            <div class="report-form" style="display:none;">
+                <div id="toolbar">
+                    <button class="oe_button oe_form_button oe_highlight" value="pdf" id="pdf">PDF</button>
+                </div>
+                <div class="container" style="width:90%;">
+                    <div class="bootstrap-table">
+                        <div class="fixed-table-container" style="border:none;">
+                            <div class="fixed-table-body">
+                                <table id="table"
+                                    data-pagination="true"
+                                    data-toggle="table"
+                                    data-toolbar="#toolbar"
+                                    data-show-columns="true"
+                                    data-height="auto"
+                                    data-classes="table table-hover table-condensed"
+                                    data-row-style="rowStyle"
+                                    data-search="true"
+                                    data-show-export="true"
+                                    data-show-toggle="true"
+                                    data-pagination-detail-h-align="left"
+                                    data-show-footer="true"
+                                    data-footer-style="footerStyle"
+                                    data-buttons-class="oe_button oe_form_button oe_highlight"
+                                    data-show-pagination-switch="true"
+                                    >
+                                    <thead style="background:none;">
+                                        <tr>
+                                            <th data-field="create_date" data-sortable="true">Fecha</th>
+                                            <th data-field="partner">Cliente</th>
+                                            <th data-field="activity" data-sortable="true">Actividad</th>
+                                            <th data-field="user">Encargado</th>
+                                            <th data-field="description">Descripcion</th>
+                                            <th data-field="task_name">Tipo</th>
+                                            <th data-field="stage">Estado</th>
+                                        </tr>
+                                    </thead>
+                                </table>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </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>

+ 37 - 0
templates.xml

@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+        <template id="eiru_reports_crm_assets" inherit_id="eiru_assets.assets">
+            <xpath expr="." position="inside">
+
+                <!-- configuration < main > -->
+                <script type="text/javascript" src="/eiru_reports_crm/static/src/js/main.js" />
+                <script type="text/javascript" src="/eiru_reports_crm/static/src/js/reporting_base.js" />
+
+                <!--
+                ======================================================================
+                    CRM
+                ======================================================================
+                -->
+
+                    <!--=============================
+                        Listado de oportunidades
+                    ==============================-->
+                    <script type="text/javascript" src="/eiru_reports_crm/static/src/js/reports/report_crm.js"/>
+
+                    <!--=============================
+                        Listado de tareas
+                    ==============================-->
+
+                    <script type="text/javascript" src="/eiru_reports_crm/static/src/js/reports/report_crm_task.js"/>
+
+                    <!--=============================
+                        Listado de Reclamos
+                    ==============================-->
+
+                    <script type="text/javascript" src="/eiru_reports_crm/static/src/js/reports/report_crm_claim.js"/>
+
+            </xpath>
+        </template>
+    </data>
+</openerp>

+ 46 - 0
views/actions.xml

@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+
+		<!--
+		======================================================================
+			CRM
+		======================================================================
+		-->
+
+			<!--
+			======================================================================
+				CRM
+			======================================================================
+			 -->
+
+			<record id="crm_action" model="ir.actions.client">
+				<field name="name">Historico de CRM</field>
+				<field name="tag">eiru_reports_crm.crm_action</field>
+			</record>
+
+			<!--
+			======================================================================
+				CRM TASK
+			======================================================================
+			 -->
+
+			 <record id="crm_task_action" model="ir.actions.client">
+				 <field name="name">Historico de Tareas CRM</field>
+				 <field name="tag">eiru_reports_crm.crm_task_action</field>
+			 </record>
+
+			 <!--
+			 ======================================================================
+				 CRM TASK
+			 ======================================================================
+			  -->
+
+			  <record id="crm_claim_action" model="ir.actions.client">
+				  <field name="name">Historico de Reclamos</field>
+				  <field name="tag">eiru_reports_crm.crm_claim_action</field>
+			  </record>
+
+
+    </data>
+</openerp>

+ 20 - 0
views/menus.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+        <!--
+        =======================================================================
+            CRM
+        =======================================================================
+         -->
+       <menuitem id="crm_parent_menu" name="CRM" parent="eiru_reports.eiru_reports_main_menu" sequence="7"/>
+
+
+           <menuitem id="crm_history_menu" parent="crm_parent_menu" name="Histórico de CRM" action="crm_action" sequence="1"/>
+
+           <menuitem id="crm_task_history_menu" parent="crm_parent_menu" name="Histórico de Tareas CRM" action="crm_task_action" sequence="2"/>
+
+           <menuitem id="crm_claim_history_menu" parent="crm_parent_menu" name="Histórico de Reclamos" action="crm_claim_action" sequence="3"/>
+
+
+    </data>
+</openerp>