deisy преди 6 години
родител
ревизия
533017b966

+ 1 - 1
__openerp__.py

@@ -7,6 +7,7 @@
     'depends': [
         'base',
         'crm',
+        'eiru_crm',
         'account',
         'eiru_assets',
         'eiru_reports',
@@ -19,6 +20,5 @@
         'templates.xml',
         'views/actions.xml',
         'views/menus.xml',
-        # 'views/payment_term.xml',
     ],
 }

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

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

+ 10 - 5
static/src/js/main.js

@@ -6,14 +6,10 @@ openerp.eiru_reports_crm= function (instance) {
     reporting_base(instance,reporting);
 
     try {
-        /*
-        ================================
-            CRM
-        ================================
-        */
         report_crm(reporting);
         report_crm_task(reporting);
         report_crm_claim(reporting);
+        report_crm_partners(reporting);
 
     } catch (e) {
         // ignorar error
@@ -40,6 +36,15 @@ openerp.eiru_reports_crm= function (instance) {
      */
     instance.web.client_actions.add('eiru_reports_crm.crm_claim_action', 'instance.eiru_reports_crm.ReportCrmClaimWidget');
 
+    /*
+    ================================================================================
+      CRM PARTNES
+    ================================================================================
+     */
+    instance.web.client_actions.add('eiru_reports_crm.crm_partners_action', 'instance.eiru_reports_crm.ReportCrmPartnersWidget');
+
+
+
 
 
 }

+ 38 - 25
static/src/js/reports/report_crm.js

@@ -97,13 +97,19 @@ function report_crm(reporting) {
     },
 
     clickAnalysisDetail: function(e, row, $element, field) {
-      if (field == 'description') {
-        this.do_action({
-          name: "CRM",
+      var self = this;
+      if (field == 'name') {
+        var model_obj = new model.web.Model('ir.model.data');
+        model_obj.call('get_object_reference', ["crm", "crm_case_form_view_oppor"]).then(function(result) {
+
+          self.do_action({
+          name: "Oportunidad",
           type: 'ir.actions.act_window',
           res_model: "crm.lead",
+          view_mode: 'form',
+          view_type: 'form',
           views: [
-            [false, 'form']
+            [result[1], 'form']
           ],
           target: 'new',
           domain: [
@@ -120,7 +126,9 @@ function report_crm(reporting) {
           },
           res_id: row.id,
         });
+      });
       }
+
       if (field === 'partner') {
         this.do_action({
           name: "Cliente",
@@ -294,9 +302,9 @@ function report_crm(reporting) {
       return defer;
     },
 
-    getResCompany: function (id) {
+    getResCompany: function(id) {
       var self = this;
-      return _.filter(self.ResCompany,function (item) {
+      return _.filter(self.ResCompany, function(item) {
         return item.id == id;
       })
     },
@@ -651,14 +659,30 @@ function report_crm(reporting) {
         var pdf_type = 'l';
         var pdf_name = 'historico_de_oportunidades_';
         var pdf_columnStyles = {
-          create_date: {columnWidth: 18,halign: 'center'},
-          name: {columnWidth: 30,  halign: 'left'},
-          description: {halign: 'left'},
-          partner: {columnWidth: 30,halign: 'left'},
-          stage: {columnWidth: 18,halign: 'center'},
-          user: {columnWidth: 30,halign: 'left'},
-          date_last_stage_update: {columnWidth: 18,halign: 'center'},
-          write_date: {columnWidth: 18,halign: 'center'},
+          create_date: {
+            columnWidth: 18,
+            halign: 'center'
+          },
+          name: {
+            columnWidth: 30,
+            halign: 'left'
+          },
+          partner: {
+
+            halign: 'left'
+          },
+          stage: {
+            columnWidth: 18,
+            halign: 'center'
+          },
+          user: {
+            columnWidth: 30,
+            halign: 'left'
+          },
+          write_date: {
+            columnWidth: 18,
+            halign: 'center'
+          },
         };
         var filter = self.getFilter();
         var pdf = new model.eiru_reports.ReportPdfWidget(self);
@@ -680,7 +704,6 @@ function report_crm(reporting) {
       var company = self.$el.find('#current-company').val();
       var store = self.$el.find('#current-store').val();
       var user = self.$el.find('#current-user').val();
-      var partner = self.$el.find('#current-partner').val();
       var stage = self.$el.find('#current-stage').val();
       var date = self.$el.find('#current-date').val();
       var desde = self.$el.find('#from').val();
@@ -717,16 +740,6 @@ function report_crm(reporting) {
         });
       }
 
-      if (partner && partner != 9999999) {
-        var ResPartner = _.filter(self.ResPartner, function(item) {
-          return item.id == partner;
-        })
-        filter.push({
-          title: 'Cliente',
-          value: ResPartner[0].name,
-        });
-      }
-
       if (stage && stage != 9999999) {
         var CrmStage = _.filter(self.CrmStage, function(item) {
           return item.id == stage;

+ 3 - 1
static/src/js/reports/report_crm_claim.js

@@ -108,7 +108,7 @@ function report_crm_claim(reporting){
         });
       }
 
-      if (field == 'description'){
+      if (field == 'name'){
         this.do_action({
           name:"Registro de Reclamos",
           type: 'ir.actions.act_window',
@@ -395,6 +395,8 @@ function report_crm_claim(reporting){
       _.each(crmclaim, function(item){
         data.push({
           id : item.id,
+          partner_id: self.valorNull(item.partner_id[0]),
+
           partner: self.valorNull(item.partner_id[1]),
           description: self.valorNull(item.description),
           name: self.valorNull(item.name),

+ 767 - 0
static/src/js/reports/report_crm_partners.js

@@ -0,0 +1,767 @@
+function report_crm_partners(reporting) {
+  "use strict";
+
+  var model = openerp;
+
+  reporting.ReportCrmPartnersWidget = reporting.Base.extend({
+    template: 'ReportCrmPartners',
+    rowsData: [],
+    content: [],
+
+    events: {
+      'click #toolbar > button': 'clickOnAction',
+      'click #generate': 'fetchGenerate',
+      'click-row.bs.table #table': 'clickAnalysisDetail',
+    },
+
+    init: function(parent) {
+      this._super(parent);
+    },
+
+    start: function() {
+      var date = new model.eiru_reports.ReportDatePickerWidget(self);
+      date.fecthFecha();
+      this.fetchInitial();
+    },
+
+    valorNull: function(dato) {
+      var valor = "";
+      if (dato) {
+        valor = dato;
+      }
+      return valor;
+    },
+
+    clickAnalysisDetail: function(e, row, $element, field) {
+      var self = this;
+
+      if (field == 'partner_name') {
+        this.do_action({
+          name: "Cliente",
+          type: 'ir.actions.act_window',
+          res_model: "res.partner",
+          views: [
+            [false, 'form']
+          ],
+          target: 'new',
+          domain: [
+            ['id', '=', row.id]
+          ],
+          context: {},
+          flags: {
+            'form': {
+              'action_buttons': false,
+              'options': {
+                'mode': 'view'
+              }
+            }
+          },
+          res_id: row.id,
+        });
+      }
+      if (field == 'name') {
+        var model_obj = new model.web.Model('ir.model.data');
+        model_obj.call('get_object_reference', ["crm", "crm_case_form_view_oppor"]).then(function(result) {
+
+          self.do_action({
+            name: "Oportunidad",
+            type: 'ir.actions.act_window',
+            res_model: "crm.lead",
+            view_mode: 'form',
+            view_type: 'form',
+            views: [
+              [result[1], 'form']
+            ],
+            target: 'new',
+            domain: [
+              ['id', '=', row.crm_id]
+            ],
+            context: {},
+            flags: {
+              'form': {
+                'action_buttons': false,
+                'options': {
+                  'mode': 'view'
+                }
+              }
+            },
+            res_id: row.crm_id,
+          });
+
+        });
+      }
+      e.stopImmediatePropagation();
+    },
+
+    fetchInitial: function() {
+      var self = this;
+      this.fetchResUser().then(function(ResUser) {
+        return ResUser;
+      }).then(function(ResUser) {
+        self.ResUser = ResUser;
+        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.fetchResStore();
+      }).then(function(ResStore) {
+        self.ResStore = ResStore;
+        if (ResStore.length > 1) {
+          self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
+          _.each(ResStore, function(item) {
+            self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
+          });
+        } else {
+          self.$el.find('.store').css('display', 'none');
+        }
+        return self.fetchCrmCaseStage();
+      }).then(function(CrmCaseStage) {
+        self.CrmCaseStage = CrmCaseStage
+        if (CrmCaseStage.length > 1) {
+          self.$el.find('#current-crm-stage').append('<option value="9999999">Todas las etapas</option>');
+          _.each(CrmCaseStage, function(item) {
+            self.$el.find('#current-crm-stage').append('<option value="' + item.id + '">' + item.name + '</option>');
+          });
+        } else {
+          self.$el.find('.crm-stage').css('display', 'none');
+        }
+        return self.fetchFirstContact();
+      }).then(function(FirstContact) {
+        self.FirstContact = FirstContact;
+        if (FirstContact.length > 1) {
+          self.$el.find('#current-contact').append('<option value="9999999">Todos los medios</option>');
+          _.each(FirstContact, function(item) {
+            self.$el.find('#current-contact').append('<option value="' + item.id + '">' + item.name + '</option>');
+          });
+        } else {
+          CrmTrackingSource
+          self.$el.find('.contact').css('display', 'none');
+        }
+        return self.fetchCrmTrackingSource();
+      }).then(function(CrmTrackingSource) {
+        self.CrmTrackingSource = CrmTrackingSource;
+        if (CrmTrackingSource.length > 1) {
+          self.$el.find('#current-source').append('<option value="9999999">Todos los origenes</option>');
+          _.each(CrmTrackingSource, function(item) {
+            self.$el.find('#current-source').append('<option value="' + item.id + '">' + item.name + '</option>');
+          });
+        } else {
+          self.$el.find('.contact').css('display', 'none');
+        }
+        return self.fetchCrmTrackingCampaign();
+      }).then(function(CrmTrackingCampaign) {
+        self.CrmTrackingCampaign = CrmTrackingCampaign;
+        if (CrmTrackingCampaign.length > 1) {
+          self.$el.find('#current-campaign').append('<option value="9999999">Todas las campañas</option>');
+          _.each(CrmTrackingCampaign, function(item) {
+            self.$el.find('#current-campaign').append('<option value="' + item.id + '">' + item.name + '</option>');
+          });
+        } else {
+          self.$el.find('.campaign').css('display', 'none');
+        }
+        return self.fetchResCountryState();
+      }).then(function(ResCountryState) {
+        self.ResCountryState = ResCountryState;
+        if (ResCountryState.length > 1) {
+          self.$el.find('#current-city').append('<option value="9999999">Todas las ciudades</option>');
+          _.each(ResCountryState, function(item) {
+            self.$el.find('#current-city').append('<option value="' + item.id + '">' + item.name + '</option>');
+          });
+        } else {
+          self.$el.find('.city').css('display', 'none');
+        }
+        return self.fetchResCurrency();
+      }).then(function(ResCurrency) {
+        self.ResCurrency = ResCurrency;
+
+      });
+      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.fetchCrmLead().then(function(CrmLead) {
+        return CrmLead;
+      }).then(function(CrmLead) {
+        self.CrmLead = CrmLead;
+        return self.fetchAccountInvoice();
+      }).then(function(AccountInvoice) {
+        self.AccountInvoice = AccountInvoice;
+        return self.fetchResPartner();
+      }).then(function(ResPartner) {
+        self.ResPartner = ResPartner;
+
+        return self.BuildTable();
+      });
+    },
+
+    fetchResStore: function() {
+      var self = this;
+      var defer = $.Deferred();
+      var field = ['id', 'name', 'company_id'];
+      var ResStore = new model.web.Model('res.store');
+      ResStore.query(field).all().then(function(results) {
+        defer.resolve(results);
+      });
+      return defer;
+    },
+
+    fetchResUser: function() {
+      var self = this;
+      var defer = $.Deferred();
+      var fields = ['id', 'name', 'store_id'];
+      var domain = [
+        ['id', '=', self.session.uid]
+      ];
+      var ResUser = new model.web.Model('res.users');
+      ResUser.query(fields).filter(domain).all().then(function(results) {
+        defer.resolve(results);
+      });
+      return defer;
+    },
+
+    fetchFirstContact: function() {
+      var self = this;
+      var defer = $.Deferred();
+      var fields = ['id', 'name', ];
+      var contact = new model.web.Model('res.partner.primer.contacto');
+      contact.query(fields).filter().all().then(function(results) {
+        defer.resolve(results);
+      });
+      return defer;
+    },
+
+    fetchCrmCaseStage: function() {
+      var self = this;
+      var defer = $.Deferred();
+      var fields = ['id', 'name', ];
+      var stage = new model.web.Model('crm.case.stage');
+      stage.query(fields).filter().all().then(function(results) {
+        defer.resolve(results);
+      });
+      return defer;
+    },
+
+    fetchCrmTrackingSource: function() {
+      var self = this;
+      var defer = $.Deferred();
+      var fields = ['id', 'name', ];
+      var source = new model.web.Model('crm.tracking.source');
+      source.query(fields).filter().all().then(function(results) {
+        defer.resolve(results);
+      });
+      return defer;
+    },
+
+    fetchCrmTrackingCampaign: function() {
+      var self = this;
+      var defer = $.Deferred();
+      var fields = ['id', 'name', ];
+      var campaign = new model.web.Model('crm.tracking.campaign');
+      campaign.query(fields).filter().all().then(function(results) {
+        defer.resolve(results);
+      });
+      return defer;
+    },
+
+    fetchResCountryState: function() {
+      var self = this;
+      var defer = $.Deferred();
+      var fields = ['id', 'name', ];
+      var city = new model.web.Model('res.country.state');
+      city.query(fields).filter().all().then(function(results) {
+        defer.resolve(results);
+      });
+      return defer;
+    },
+
+    fetchCrmLead: function() {
+      var self = this;
+      var defer = $.Deferred();
+      var company = self.$el.find('#current-company').val();
+      var store = self.$el.find('#current-store').val();
+      var type = self.$el.find('#current-type').val();
+      var stage = self.$el.find('#current-crm-stage').val();
+      var source = self.$el.find('#current-source').val();
+      var campaign = self.$el.find('#current-campaign').val();
+      var fields = ['id', 'name', 'partner_id', 'stage_id', 'source_id', 'create_date'];
+      var domain = [
+        ['type', '=', 'opportunity']
+      ];
+
+      if (company && company != 9999999) {
+        domain.push(['company_id', '=', parseInt(company)]);
+      }
+
+      if (store && store != 9999999) {
+        var user_ids = _.map(_.filter(self.ResUser, function(item) {
+          return item.store_id[0] == store;
+        }), function(map) {
+          return map.id;
+        });
+        domain.push(['user_id', 'in', user_ids]);
+      }
+
+      if (type && type != 9999999) {
+        if (type == 'leads') {
+          domain.push(['stage_id.code', '=', 'LEAD_NO_DELETE'])
+        }
+
+        if (type == 'prospect' || type == 'customer') {
+          domain.push('|', ['stage_id.code', '!=', 'LEAD_NO_DELETE'], ['stage_id.code', '=', null])
+        }
+      }
+
+      if (stage && stage != 9999999) {
+        domain.push(['stage_id', '=', parseInt(stage)])
+      }
+
+      if (source && source != 9999999) {
+        domain.push(['source_id', '=', parseInt(source)])
+      }
+      if (campaign && campaign != 9999999) {
+        domain.push(['campaign_id', '=', parseInt(campaign)])
+      }
+
+      var contact = new model.web.Model('crm.lead');
+      contact.query(fields).filter(domain).all().then(function(results) {
+        defer.resolve(results);
+      });
+      return defer;
+    },
+
+    getCrmLead: function(id) {
+      var self = this;
+      return _.filter(self.CrmLead, function(item) {
+        return item.partner_id[0] == id;
+      })
+    },
+
+    fetchAccountInvoice: function(id) {
+      var self = this;
+      var defer = $.Deferred();
+      var fields = ['id', 'name', 'partner_id'];
+
+      var partner_ids = _.map(self.CrmLead, function(item) {
+        return item.partner_id[0];
+      });
+
+      var domain = [
+        ['partner_id', 'in', partner_ids],
+      ];
+      var contact = new model.web.Model('account.invoice');
+      contact.query(fields).filter(domain).all().then(function(results) {
+        defer.resolve(results);
+      });
+      return defer;
+
+    },
+
+    fetchResPartner: function() {
+      var self = this;
+      var defer = $.Deferred();
+
+      var fields = ['id', 'ruc', 'name', 'street', 'state_id', 'phone', 'mobile', 'email'];
+      var type = self.$el.find('#current-type').val();
+      var contact = self.$el.find('#current-contact').val();
+      var city = self.$el.find('#current-city').val();
+
+
+      var partner_ids = _.map(self.CrmLead, function(item) {
+        return item.partner_id[0];
+      });
+
+      var domain = [
+        ['active', '=', true],
+        ['id', 'in', partner_ids],
+      ];
+
+      if (type && type != 9999999) {
+        if (type == 'leads' || type == 'prospect') {
+          domain.push(['customer', '=', false])
+        }
+
+        if (type == 'customer') {
+          domain.push(['customer', '=', true])
+        }
+      }
+
+      if (contact && contact != 9999999) {
+        domain.push(['primer_contacto', '=', parseInt(contact)])
+      }
+
+      if (city && city != 9999999) {
+        domain.push(['state_id', '=', parseInt(city)])
+      }
+
+      var ResPartner = new model.web.Model('res.partner');
+      ResPartner.query(fields).filter(domain).all().then(function(results) {
+        defer.resolve(results);
+      });
+      return defer;
+    },
+
+    getResPartner: function() {
+      var self = this;
+      var ResPartner = self.ResPartner;
+      var type = self.$el.find('#current-type').val();
+
+      var ids = _.map(self.AccountInvoice, function(item) {
+        return item.partner_id[0];
+      });
+
+      if (type == 'leads' || type == 'prospect') {
+        ResPartner = _.filter(ResPartner, function(a) {
+          return !_.find(ids, function(b) {
+            return b === a.id;
+          });
+        })
+      }
+      if (type == 'customer') {
+        ResPartner = _.filter(ResPartner, function(a) {
+          return _.find(ids, function(b) {
+            return b === a.id;
+          });
+        })
+      }
+      return ResPartner;
+    },
+
+
+    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;
+    },
+
+
+    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 model.web.Model('res.currency');
+      ResCurrency.query(fields).filter(domain).all().then(function(results) {
+        defer.resolve(results);
+      });
+      return defer;
+    },
+
+
+    getResCompany: function(id) {
+      var self = this;
+      return _.filter(self.ResCompany, function(item) {
+        return item.id == id;
+      })
+    },
+
+
+    getResCurrency: function(id) {
+      var self = this;
+      return _.filter(self.ResCurrency, function(item) {
+        return item.id === id;
+      })
+    },
+
+
+    BuildTable: function() {
+      var self = this;
+      var data = [];
+      var info = [];
+      var company = $('#current-company').val();
+      if (company && company != 9999999) {
+        var ResCompany = self.getResCompany(company).shift();
+        var CurrencyBase = self.getResCurrency(ResCompany.currency_id[0]).shift();
+      } else {
+        var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
+      }
+      var ResPartner = self.getResPartner();
+      _.each(ResPartner, function(item) {
+        info = [];
+        var CrmLead = self.getCrmLead(item.id);
+        _.each(CrmLead, function(index) {
+          info.push({
+            crm_id: index.id,
+            create_date: moment(index.create_date).format("DD/MM/YYYY"),
+            name: index.name,
+            stage_name: index.stage_id[1],
+            source_name: index.source_id[1],
+          })
+
+        });
+        data.push({
+          id: item.id,
+          ruc: self.valorNull(item.ruc),
+          partner_name: item.name,
+          street: self.valorNull(item.street),
+          state_id: self.valorNull(item.state_id[1]),
+          phone: self.valorNull(item.phone),
+          mobile: self.valorNull(item.mobile),
+          email: self.valorNull(item.email),
+
+          decimal_places: CurrencyBase.decimal_places,
+          thousands_separator: CurrencyBase.thousands_separator,
+          decimal_separator: CurrencyBase.decimal_separator,
+
+          info: info,
+        });
+      });
+
+      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();
+    },
+
+    /*====================================================================
+        LOAD BOOTSTRAP TABLE
+    ====================================================================*/
+    loadTable: function(rowsTable) {
+      var self = this;
+      var data = [];
+      self.rowsData = rowsTable;
+      var table = this.$el.find('#table');
+
+      table.bootstrapTable({
+        data: rowsTable,
+        detailView: true,
+        onExpandRow: function(index, row, $detail) {
+          $detail.html('<div class="panel panel-first-style"><div class="panel-heading panel-header-first-style">Oportunidades del contacto</div><table id="table2"></table></div>').find('table').bootstrapTable({
+            columns: [{
+                field: 'create_date',
+                title: 'Creado el',
+                align: 'left',
+              },
+              {
+                field: 'name',
+                title: 'Oportunidad',
+                align: 'left',
+                class: 'hover',
+              },
+              {
+                field: 'stage_name',
+                title: 'Estado',
+                align: 'left',
+              },
+              {
+                field: 'source_name',
+                title: 'Origen de la Oportunidad',
+                align: 'left',
+              },
+            ],
+
+            data: row.info,
+          })
+          $('#table2').removeClass('table-hover').addClass('table-no-bordered');
+          $('thead').css('background', 'none');
+        }
+      })
+
+      table.bootstrapTable('load', rowsTable);
+    },
+
+    /*====================================================================
+        PRINT PDF
+    ====================================================================*/
+    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');
+
+      row.push({})
+
+      if (action === 'pdf') {
+        var data = _.map(column, function(val) {
+          return val.field
+        });
+        _.each(_.map(column, function(val) {
+          return val
+        }), function(item) {
+          getColumns.push([{
+            title: item.title,
+            dataKey: item.field
+          }]);
+        });
+        /*
+        ============================================================
+            CONFIGURACION DEL PDF
+        ============================================================
+        */
+        var pdf_title = 'Contactos del CRM.';
+        var pdf_type = '';
+        var pdf_name = 'contactos_del_crm_';
+        var pdf_columnStyles = {
+          ruc: {
+            columnWidth: 18,
+            halign: 'left'
+          },
+          partner_name: {
+            columnWidth: 25,
+            halign: 'left'
+          },
+          street: {
+            halign: 'left'
+          },
+          state_id: {
+            halign: 'left'
+          },
+          phone: {
+            columnWidth: 25,
+            halign: 'left'
+          },
+          mobile: {
+            columnWidth: 25,
+            halign: 'left'
+          },
+          email: {
+            columnWidth: 40,
+            halign: 'left'
+          },
+        };
+        /*
+        ============================================================
+            LLAMAR FUNCION DE IMPRESION
+        ============================================================
+        */
+        var filter = self.getFilter();
+        var pdf = new model.eiru_reports.ReportPdfWidget(self);
+        pdf.drawPDF(
+          _.flatten(getColumns),
+          row,
+          ResCompany,
+          pdf_title,
+          pdf_type,
+          pdf_name,
+          pdf_columnStyles,
+          filter,
+        );
+      }
+    },
+    getFilter: function() {
+      var self = this;
+      var company = self.$el.find('#current-company').val();
+      var store = self.$el.find('#current-store').val();
+      var stage = self.$el.find('#current-crm-stage').val();
+      var type = self.$el.find('#current-type').val();
+      var contact = self.$el.find('#current-contact').val();
+      var source = self.$el.find('#current-source').val();
+      var campaign = self.$el.find('#current-campaign').val();
+      var city = self.$el.find('#current-city').val();
+
+      var filter = [];
+
+      if (company && company != 9999999) {
+        var ResCompany = _.filter(self.ResCompany, function(item) {
+          return item.id == company;
+        });
+        filter.push({
+          title: 'Empresa',
+          value: ResCompany[0].name,
+        });
+      }
+      if (store && store != 9999999) {
+        var ResStore = _.filter(self.ResStore, function(item) {
+          return item.id == store;
+        });
+        filter.push({
+          title: 'Sucursal',
+          value: ResStore[0].name,
+        });
+      }
+      if (stage && stage != 9999999) {
+        var CrmCaseStage = _.filter(self.CrmCaseStage, function(item) {
+          return item.id == stage;
+        });
+        filter.push({
+          title: 'Etapa',
+          value: CrmCaseStage[0].name,
+        });
+      }
+
+      if (type && type != 9999999) {
+        filter.push({
+          title: 'Tipo de contacto',
+          value: $('#current-type option:selected').text(),
+        })
+      }
+      if (contact && contact != 9999999) {
+        var FirstContact = _.filter(self.FirstContact, function(item) {
+          return item.id == contact;
+        });
+        filter.push({
+          title: 'Primer contacto',
+          value: FirstContact[0].name,
+        });
+      }
+      if (source && source != 9999999) {
+        var CrmTrackingSource = _.filter(self.CrmTrackingSource, function(item) {
+          return item.id == source;
+        });
+        filter.push({
+          title: 'Origen',
+          value: CrmTrackingSource[0].name,
+        });
+      }
+      if (campaign && campaign != 9999999) {
+        var CrmTrackingCampaign = _.filter(self.CrmTrackingCampaign, function(item) {
+          return item.id == campaign;
+        });
+        filter.push({
+          title: 'Campaña',
+          value: CrmTrackingCampaign[0].name,
+        });
+      }
+      if (city && city != 9999999) {
+        var ResCountryState = _.filter(self.ResCountryState, function(item) {
+          return item.id == city;
+        });
+        filter.push({
+          title: 'Ciudad',
+          value: ResCountryState[0].name,
+        });
+      }
+      return filter;
+    },
+  });
+}

+ 35 - 3
static/src/js/reports/report_crm_task.js

@@ -97,6 +97,7 @@ function report_crm_task(reporting) {
     },
 
     clickAnalysisDetail: function(e, row, $element, field) {
+      var self = this;
       if (field == 'partner') {
         this.do_action({
           name: "Cliente",
@@ -121,7 +122,7 @@ function report_crm_task(reporting) {
           res_id: row.partner_id,
         });
       }
-      if (field === 'activity') {
+      if (field === 'tarea') {
         this.do_action({
           name: "Registro de Tareas",
           type: 'ir.actions.act_window',
@@ -145,6 +146,36 @@ function report_crm_task(reporting) {
           res_id: row.id,
         });
       }
+      if (field === 'opportunity_name') {
+        var model_obj = new model.web.Model('ir.model.data');
+        model_obj.call('get_object_reference', ["crm", "crm_case_form_view_oppor"]).then(function(result) {
+
+          self.do_action({
+          name: "Oportunidad",
+          type: 'ir.actions.act_window',
+          res_model: "crm.lead",
+          view_mode: 'form',
+          view_type: 'form',
+          views: [
+            [result[1], 'form']
+          ],
+          target: 'new',
+          domain: [
+            ['id', '=', row.opportunity_id]
+          ],
+          context: {},
+          flags: {
+            'form': {
+              'action_buttons': false,
+              'options': {
+                'mode': 'view'
+              }
+            }
+          },
+          res_id: row.opportunity_id,
+        });
+      });
+      }
       e.stopImmediatePropagation();
     },
 
@@ -480,11 +511,12 @@ function report_crm_task(reporting) {
         data.push({
           id: item.id,
           partner_id: self.valorNull(item.partner_id[0]),
+          opportunity_id: self.valorNull(item.opportunity_id[0]),
 
           create_date: moment(item.create_date).format("DD/MM/YYYY"),
           user: item.user_id[1],
           partner: self.valorNull(item.partner_id[1]),
-          activity: self.valorNull(item.name),
+          tarea: self.valorNull(item.name),
           description: self.valorNull(item.description),
           opportunity_name: self.valorNull(item.opportunity_id[1]),
           next_date: moment(item.date_action_next).format("DD/MM/YYYY"),
@@ -542,7 +574,7 @@ function report_crm_task(reporting) {
           create_date: {columnWidth: 16,halign: 'center'},
           user: {columnWidth: 30,halign: 'left'},
           partner: {columnWidth: 30,halign: 'left'},
-          activity: {columnWidth: 30,halign: 'left'},
+          tarea: {columnWidth: 30,halign: 'left'},
           description: {halign: 'left'},
           opportunity_name: {columnWidth: 25,halign: 'left'},
           next_date: {columnWidth: 18,halign: 'center'},

+ 3 - 9
static/src/reports/report_crm.xml

@@ -20,10 +20,6 @@
             <label>Responsable</label>
             <select id="current-user" class="form-control form-control-sm"></select>
           </div>
-          <div class="col-lg-3 partner filter-style">
-            <label>Clientes</label>
-            <select id="current-partner" class="form-control form-control-sm"></select>
-          </div>
           <div class="col-lg-3 stage filter-style">
             <label>Etapas</label>
             <select id="current-stage" class="form-control form-control-sm"></select>
@@ -32,7 +28,7 @@
           <div class="col-lg-3 filter-style">
             <label>Fecha de Creación</label>
             <select id="current-date" class="form-control form-control-sm">
-              <option value="9999999">Sin fechas</option>
+              <option value="9999999">Todas las fechas</option>
               <option value="today">Hoy</option>
               <option value="yesterday">Ayer</option>
               <option value="currentMonth">Mes Actual</option>
@@ -98,12 +94,10 @@
             <thead style="background:none;">
               <tr>
                 <th data-field="create_date" data-sortable="true" data-align="center">Fecha Creación</th>
-                <th data-field="name" data-sortable="true" data-align="left">Asunto</th>
-                <th data-field="description" data-align="left">Descripcion</th>
-                <th data-field="partner" data-sortable="true" data-align="left">Cliente</th>
+                <th class="hover" data-field="name" data-align="left">Oportunidad</th>
+                <th class="hover" data-field="partner" data-sortable="true" data-align="left">Cliente</th>
                 <th data-field="stage" data-sortable="true" data-align="center">Etapa</th>
                 <th data-field="user" data-sortable="true" data-align="left">Responsable</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>

+ 3 - 3
static/src/reports/report_crm_claim.xml

@@ -31,7 +31,7 @@
           <div class="col-lg-3 filter-style">
             <label>Fechas</label>
             <select id="current-date" class="form-control form-control-sm">
-              <option value="9999999">Sin fechas</option>
+              <option value="9999999">Todas las fechas</option>
               <option value="today">Hoy</option>
               <option value="yesterday">Ayer</option>
               <option value="currentMonth">Mes Actual</option>
@@ -95,8 +95,8 @@
             <thead style="background:none;">
               <tr>
                 <th data-field="date" data-sortable="true">Fecha</th>
-                <th data-field="partner">Cliente</th>
-                <th data-field="name">Motivo del Reclamo</th>
+                <th class="hover" data-field="partner">Cliente</th>
+                <th class="hover" data-field="name">Motivo del Reclamo</th>
                 <th data-field="description">Descripción</th>
                 <th data-field="user">Responsable</th>
                 <th data-field="stage_name">Estado</th>

+ 99 - 0
static/src/reports/report_crm_partners.xml

@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+  <t t-name="ReportCrmPartners">
+    <div class="report_view">
+      <div class="reporting_page_header">
+        <h1 class="report_title">Contactos del CRM</h1>
+      </div>
+      <div class="container search-form" style="border-bottom:1px solid #eee; width:95%;">
+        <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 store filter-style">
+            <label>Sucursal</label>
+            <select id="current-store" class="form-control form-control-sm"></select>
+          </div>
+
+          <div class="col-lg-3 crm-stage filter-style">
+            <label>Etapa del CRM</label>
+            <select id="current-crm-stage" class="form-control form-control-sm"></select>
+          </div>
+          <div class="col-lg-3 type filter-style">
+            <label>Tipo de contacto</label>
+            <select id="current-type" class="form-control form-control-sm">
+              <option value="9999999">Todos los tipos</option>
+              <option value="leads">Iniciativas</option>
+              <option value="prospect">Prospectos</option>
+              <option value="customer">Clientes</option>
+            </select>
+          </div>
+          <div class="col-lg-3 contact filter-style">
+            <label>Primer contacto</label>
+            <select id="current-contact" class="form-control form-control-sm"></select>
+          </div>
+          <div class="col-lg-3 source filter-style">
+            <label>Origen de la oportunidad</label>
+            <select id="current-source" class="form-control form-control-sm"></select>
+          </div>
+          <div class="col-lg-3 campaign filter-style">
+            <label>Campaña</label>
+            <select id="current-campaign" class="form-control form-control-sm"></select>
+          </div>
+          <div class="col-lg-3 city filter-style">
+            <label>Ciudad</label>
+            <select id="current-city" class="form-control form-control-sm"></select>
+          </div>
+        </div>
+        <div class="row">
+          <div class="text-center" style="padding-top:20px;">
+            <button id="generate" class="myButton" aria-label="Left Align" style="color:#fff;display:none;">
+              Generar
+            </button>
+          </div>
+          <br/>
+        </div>
+      </div>
+
+      <div class="report-form" style="display:none;">
+        <div id="toolbar">
+          <button class="oe_button myButton" value="pdf">Imprimir Informe</button>
+        </div>
+        <div class="container" style="width:95%;">
+          <table
+            id="table"
+            data-pagination="true"
+            data-toggle="table"
+            data-toolbar="#toolbar"
+            data-show-columns="true"
+            data-classes="table table-hover table-condensed  table-no-bordered"
+            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 myButton"
+            data-show-pagination-switch="true"
+            data-page-size="10"
+            data-search-on-enter-key="true"
+            data-undefined-text=" ">
+            <thead style="background:none;">
+              <tr>
+                <th data-field="ruc" data-align="left">RUC.</th>
+                <th class="hover" data-field="partner_name" data-align="left">Nombre y Apellido</th>
+                <th data-field="street" data-align="left">Dirección</th>
+                <th data-field="state_id" data-align="left">Ciudad</th>
+                <th data-field="phone" data-align="left">Teléfono</th>
+                <th data-field="mobile" data-align="left">Celular</th>
+                <th data-field="email" data-align="left">Email</th>
+              </tr>
+            </thead>
+          </table>
+        </div>
+      </div>
+    </div>
+  </t>
+</template>

+ 12 - 11
static/src/reports/report_crm_task.xml

@@ -34,7 +34,7 @@
           </div>
 
           <div class="col-lg-3 task-type filter-style">
-            <label>Tipo de Actividad</label>
+            <label>Tipo de Tarea</label>
             <select id="current-task-type" class="form-control form-control-sm"></select>
           </div>
 
@@ -46,7 +46,7 @@
           <div class="col-lg-3 filter-style">
             <label>Fecha de Próx Acción</label>
             <select id="current-date" class="form-control form-control-sm">
-              <option value="9999999">Sin fechas</option>
+              <option value="9999999">Todas las fechas</option>
               <option value="today">Hoy</option>
               <option value="yesterday">Ayer</option>
               <option value="currentMonth">Mes Actual</option>
@@ -56,18 +56,18 @@
           </div>
         </div>
 
-        <div class="row" >
+        <div class="row">
           <div class="datepicker" style="display:none;">
             <div class="col-lg-3 filter-style col-md-offset-3">
               <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"/>
+                <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"/>
+                <input type="text" id="to" class="form-control" aria-describedby="basic-addon1"/>
               </div>
             </div>
           </div>
@@ -76,7 +76,7 @@
         <div class="row">
           <div class="text-center" style="padding-top:20px;">
             <button id="generate" class="myButton" aria-label="Left Align" style="color:#fff;display:none;">
-                Generar
+              Generar
             </button>
           </div>
           <br/>
@@ -88,7 +88,8 @@
           <button class="oe_button oe_form_button myButton" value="pdf" id="pdf">Imprimir Informe</button>
         </div>
         <div class="container" style="width:95%;">
-          <table id="table"
+          <table
+            id="table"
             data-pagination="true"
             data-toggle="table"
             data-toolbar="#toolbar"
@@ -107,14 +108,14 @@
             data-page-size="10"
             data-search-on-enter-key="true"
             data-undefined-text=" ">
-            <thead style="background:none;">
+            <thead style="background:none">
               <tr>
                 <th data-field="create_date" data-sortable="true">Fecha</th>
                 <th data-field="user">Encargado</th>
-                <th data-field="partner">Cliente</th>
-                <th data-field="activity" data-sortable="true">Actividad</th>
+                <th class="hover" data-field="partner">Cliente</th>
+                <th class="hover" data-field="tarea" data-sortable="true">Tarea</th>
                 <th data-field="description">Descripcion</th>
-                <th data-field="opportunity_name">Oportunidad</th>
+                <th class="hover" data-field="opportunity_name">Oportunidad</th>
                 <th data-field="next_date">Fecha Próx Acción</th>
                 <th data-field="task_name">Tipo</th>
                 <th data-field="state">Estado</th>

+ 20 - 27
templates.xml

@@ -1,38 +1,31 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <openerp>
-    <data>
-        <template id="eiru_reports_crm_assets" inherit_id="eiru_assets.assets">
-            <xpath expr="." position="inside">
-                <link rel="stylesheet" href="/eiru_reports_crm/static/src/css/custom.css"/>
+  <data>
+    <template id="eiru_reports_crm_assets" inherit_id="eiru_assets.assets">
+      <xpath expr="." position="inside">
+        <link rel="stylesheet" href="/eiru_reports_crm/static/src/css/custom.css"/>
 
-                <!-- 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" />
+        <!-- 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 -->
 
-                    <!--=============================
-                        Listado de oportunidades
-                    ==============================-->
-                    <script type="text/javascript" src="/eiru_reports_crm/static/src/js/reports/report_crm.js"/>
+        <script type="text/javascript" src="/eiru_reports_crm/static/src/js/reports/report_crm.js"/>
 
-                    <!--=============================
-                        Listado de tareas
-                    ==============================-->
+        <!-- Listado de tareas -->
 
-                    <script type="text/javascript" src="/eiru_reports_crm/static/src/js/reports/report_crm_task.js"/>
+        <script type="text/javascript" src="/eiru_reports_crm/static/src/js/reports/report_crm_task.js"/>
 
-                    <!--=============================
-                        Listado de Reclamos
-                    ==============================-->
+        <!-- Listado de Reclamos -->
 
-                    <script type="text/javascript" src="/eiru_reports_crm/static/src/js/reports/report_crm_claim.js"/>
+        <script type="text/javascript" src="/eiru_reports_crm/static/src/js/reports/report_crm_claim.js"/>
 
-            </xpath>
-        </template>
-    </data>
+        <!-- Contactos CRM -->
+
+        <script type="text/javascript" src="/eiru_reports_crm/static/src/js/reports/report_crm_partners.js"/>
+
+      </xpath>
+    </template>
+  </data>
 </openerp>

+ 21 - 41
views/actions.xml

@@ -2,45 +2,25 @@
 <openerp>
 	<data>
 
-		<!--
-		======================================================================
-			CRM
-		======================================================================
-		-->
-
-			<!--
-			======================================================================
-				CRM
-			======================================================================
-			 -->
-
-			<record id="crm_action" model="ir.actions.client">
-				<field name="name">Histórico de Oportunidades</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">Histórico de Tareas</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">Histórico de Reclamos</field>
-				  <field name="tag">eiru_reports_crm.crm_claim_action</field>
-			  </record>
-
-
-    </data>
+		<record id="crm_action" model="ir.actions.client">
+			<field name="name">Histórico de Oportunidades</field>
+			<field name="tag">eiru_reports_crm.crm_action</field>
+		</record>
+
+		<record id="crm_task_action" model="ir.actions.client">
+			<field name="name">Histórico de Tareas</field>
+			<field name="tag">eiru_reports_crm.crm_task_action</field>
+		</record>
+
+		<record id="crm_claim_action" model="ir.actions.client">
+			<field name="name">Histórico de Reclamos</field>
+			<field name="tag">eiru_reports_crm.crm_claim_action</field>
+		</record>
+
+		<record id="crm_partners_action" model="ir.actions.client">
+			<field name="name">Contactos CRM</field>
+			<field name="tag">eiru_reports_crm.crm_partners_action</field>
+		</record>
+
+	</data>
 </openerp>

+ 9 - 12
views/menus.xml

@@ -1,20 +1,17 @@
 <?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"/>
+  <data>
+    <!-- main menu -->
+    <menuitem id="crm_parent_menu" name="CRM" parent="eiru_reports.eiru_reports_main_menu" sequence="7"/>
 
+    <!-- sub menu -->
+    <menuitem id="crm_partners_menu" parent="crm_parent_menu" name="Contactos de CRM" action="crm_partners_action" sequence="1"/>
 
-           <menuitem id="crm_history_menu" parent="crm_parent_menu" name="Histórico de Oportunidades" action="crm_action" sequence="1"/>
+    <menuitem id="crm_history_menu" parent="crm_parent_menu" name="Histórico de Oportunidades" action="crm_action" sequence="2"/>
 
-           <menuitem id="crm_task_history_menu" parent="crm_parent_menu" name="Histórico de Tareas" action="crm_task_action" sequence="2"/>
+    <menuitem id="crm_task_history_menu" parent="crm_parent_menu" name="Histórico de Tareas" action="crm_task_action" sequence="3"/>
 
-           <menuitem id="crm_claim_history_menu" parent="crm_parent_menu" name="Histórico de Reclamos" action="crm_claim_action" sequence="3"/>
+    <menuitem id="crm_claim_history_menu" parent="crm_parent_menu" name="Histórico de Reclamos" action="crm_claim_action" sequence="4"/>
 
-
-    </data>
+  </data>
 </openerp>