deisy před 5 roky
rodič
revize
b51f27a2af

+ 104 - 224
static/src/js/reports/report_delivery_baco.js

@@ -7,31 +7,26 @@ function report_delivery_baco(reporting){
     template: 'ReportDeliveryWidget',
     rowsData: [],
     content: [],
-    modules: ['point_of_sale'],
 
     events: {
       'click #toolbar > button': 'clickOnAction',
       'click #generate': 'fetchGenerate',
       'change #current-company': 'updateSelections',
-      'change #current-period': 'updatePeriodSelections',
-      'change #current-date': 'ShowDateRange',
+      'change #current-store': 'updateUsers',
     },
 
     init: function(parent) {
       this._super(parent);
     },
 
-
     start: function () {
-         var table = this.$el.find('#table');
-         table.bootstrapTable({data : self.rowsData});
-        var date = new model.eiru_reports.ReportDatePickerWidget(self);
-         date.fecthFecha();
-         this.fetchInitial();
+      var table = this.$el.find('#table');
+      table.bootstrapTable({data : self.rowsData});
+      var date = new model.eiru_reports.ReportDatePickerWidget(self);
+      date.fecthFecha();
+      this.fetchInitial();
      },
 
-
-
     valorNull: function(dato) {
       var valor = "";
       if (dato) {
@@ -47,28 +42,22 @@ function report_delivery_baco(reporting){
       });
     },
 
-    ShowDateRange: function() {
-      var self = this;
-      var date = self.$el.find('#current-date').val();
-      if (date == 'range') {
-        self.$el.find('.datepicker').css('display', 'block');
-      }
-      if (date != 'range') {
-        self.$el.find('.datepicker').css('display', 'none');
-      }
-
-    },
 
     fetchInitial: function() {
       var self = this;
-      self.fecthIrModuleModule().then(function(IrModuleModule) {
-        return IrModuleModule;
-      }).then(function(IrModuleModule) {
-        self.IrModuleModule = IrModuleModule;
-        return self.fetchResUser();
+      self.fetchResUser().then(function(ResUser) {
+        return ResUser;
       }).then(function(ResUser) {
         self.ResUser = ResUser;
-        self.fecthCheckType();
+        if (ResUser.length > 0) {
+          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');
+        }
+
         return self.fetchResCompany();
       }).then(function(ResCompany) {
         self.ResCompany = ResCompany;
@@ -129,45 +118,16 @@ function report_delivery_baco(reporting){
         return self.fetchAccountInvoice();
       }).then(function(AccountInvoice) {
         self.AccountInvoice = AccountInvoice;
-        return self.fetchPosOrder();
-      }).then(function(PosOrder) {
-        self.PosOrder = PosOrder;
         return self.fetchDelivery();
       }).then(function(Delivery) {
         self.Delivery = Delivery;
+        return self.fetchResUser();
+      }).then(function(ResUser) {
+        self.ResUser = ResUser;
         return self.BuildTable();
       });
     },
 
-    /*=====================================================================
-        IR MODULE
-    =====================================================================*/
-    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('point_of_sale');
-      if (modules.length == 0) {
-        self.$el.find('.type').css('display', 'none');
-      }
-    },
-
     fetchAccountJournal: function() {
       var self = this;
       var domain = [
@@ -180,7 +140,6 @@ function report_delivery_baco(reporting){
       });
     },
 
-
     /*=====================================================================
         USER
     =====================================================================*/
@@ -188,9 +147,21 @@ function report_delivery_baco(reporting){
       var self = this;
       var defer = $.Deferred();
       var fields = ['id', 'name', 'store_id'];
+      var user = self.$el.find('#current-user').val();
+      var store = self.$el.find('#current-store').val();
+
       var domain = [
         ['active', '=', true]
       ];
+
+      if(store && store != 9999999){
+        domain.push(['store_id','=', parseInt(store)]);
+      }
+
+      if (user && user != 9999999) {
+        domain.push(['id', '=', parseInt(user)]);
+      }
+
       var ResUser = new model.web.Model('res.users');
       ResUser.query(fields).filter(domain).all().then(function(results) {
         defer.resolve(results);
@@ -226,7 +197,6 @@ function report_delivery_baco(reporting){
       return defer;
     },
 
-
     /*=====================================================================
         ACCOUNT PERIOD
     =====================================================================*/
@@ -244,7 +214,6 @@ function report_delivery_baco(reporting){
       return defer;
     },
 
-
     /*====================================================================
         RES CURRENCY
     ====================================================================*/
@@ -266,125 +235,49 @@ function report_delivery_baco(reporting){
         ACCOUNT INVOICE
     ====================================================================*/
 
-
     fetchAccountInvoice: function () {
-        var self = this;
-        var defer = $.Deferred();
-
-        var store = self.$el.find('#current-store').val();
-        var period = self.$el.find('#current-period').val();
-        var company = self.$el.find('#current-company').val();
-
-
-        if (store && store != 9999999) {
-          var journal_ids = _.map(_.filter(self.AccountJournal, function(item) {
-            return item.store_ids[0] == store;
-          }), function(map) {
-            return map.id;
-          });
-        } else {
-          var journal_ids = _.flatten(_.map(self.AccountJournal, function(item) {
-            return item.id;
-          }));
-        }
-
-        var domain = [
-          ['state', 'in', ['open', 'paid']],
-          ['type', '=', 'out_invoice'],
-          ['journal_id', 'in', journal_ids],
-        ];
-
-        if (company && company != 9999999) {
-          domain.push(['company_id', '=', parseInt(company)]);
-        }
-
+      var self = this;
+      var defer = $.Deferred();
 
-        if (period && period != 9999999) {
-          domain.push(['period_id', '=', parseInt(period)]);
-        }
+      var store = self.$el.find('#current-store').val();
+      var period = self.$el.find('#current-period').val();
+      var company = self.$el.find('#current-company').val();
 
-        var field =['id', 'number', 'state','type','amount_total','user_id','company_id','period_id','date_invoice','journal_id', 'is_delivery','delivery_type'];
-        var AccountInvoice = new model.web.Model('account.invoice');
-        AccountInvoice.query(field).filter(domain).all().then(function (results) {
-          defer.resolve(results);
+      if (store && store != 9999999) {
+        var journal_ids = _.map(_.filter(self.AccountJournal, function(item) {
+          return item.store_ids[0] == store;
+        }), function(map) {
+          return map.id;
         });
-        return defer;
-      },
-
-
+      } else {
+        var journal_ids = _.flatten(_.map(self.AccountJournal, function(item) {
+          return item.id;
+        }));
+      }
 
+      var domain = [
+        ['state', 'in', ['open', 'paid']],
+        ['type', '=', 'out_invoice'],
+        ['journal_id', 'in', journal_ids],
+      ];
 
-    fetchPosOrder: function() {
-      var self = this;
-      var defer = $.Deferred();
-      var type = $('#current-type').val();
-      var modules = self.checkModel('point_of_sale');
-      if (type && modules.length > 0) {
-        if (type != 'sale') {
-          var store = self.$el.find('#current-store').val();
-          var company = self.$el.find('#current-company').val();
-          var journal = self.$el.find('#current-journal').val();
-          var date = self.$el.find('#current-date').val();
-          var desde = self.$el.find('#from').val();
-          var hasta = self.$el.find('#to').val();
-          if (store && store != 9999999) {
-            var journal_ids = _.map(_.filter(self.AccountJournal, function(item) {
-              return item.store_ids[0] == store;
-            }), function(map) {
-              return map.id;
-            });
-          } else {
-            var journal_ids = _.flatten(_.map(self.AccountJournal, function(item) {
-              return item.id;
-            }));
-          }
-          var domain = [
-            ['state', 'not in', ['draft', 'cancel']],
-            ['sale_journal', 'in', journal_ids],
-          ];
-          if (company && company != 9999999) {
-            domain.push(['company_id', '=', parseInt(company)]);
-          }
-          if (journal && journal != 9999999) {
-            domain.push(['sale_journal', '=', parseInt(journal)]);
-          }
+      if (company && company != 9999999) {
+        domain.push(['company_id', '=', parseInt(company)]);
+      }
 
-          if (date && date != 9999999) {
-            if (date == 'range') {
-              if (desde) {
-                var date = desde.split('/')
-                date = (date[2] + "-" + date[1] + "-" + date[0]);
-                domain.push(['date_order', '>=', date]);
-              }
-            }
-            if (date == 'today') {
-              var today = moment().format('YYYY-MM-DD 00:00:00');
-              domain.push(['date_order', '>=', today]);
-            }
-            if (date == 'yesterday') {
-              var yesterday = moment().add(-1, 'days').format('YYYY-MM-DD 00:00:00');
-              domain.push(['date_order', '>=', yesterday]);
-            }
-            if (date == 'currentMonth') {
-              var currentMonth = moment().format('YYYY-MM');
-              domain.push(['date_order', 'like', currentMonth]);
-            }
-            if (date == 'lastMonth') {
-              var lastMonth = moment().add(-1, 'months').format('YYYY-MM');
-              domain.push(['date_order', 'like', lastMonth]);
-            }
-          }
-          var PosOrder = new model.web.Model('account.invoice');
-          return PosOrder.call('getPosOrder', [domain], {
-            context: new model.web.CompoundContext()
-          });
-        }
-      } else {
-        var PosOrder = [];
-        return PosOrder;
+      if (period && period != 9999999) {
+        domain.push(['period_id', '=', parseInt(period)]);
       }
+
+      var field =['id', 'number', 'state','type','amount_total','user_id','company_id','period_id','date_invoice','journal_id', 'is_delivery','delivery_type'];
+      var AccountInvoice = new model.web.Model('account.invoice');
+      AccountInvoice.query(field).filter(domain).all().then(function (results) {
+        defer.resolve(results);
+      });
+        return defer;
     },
 
+
     fetchDelivery: function() {
       var self = this;
       var defer = $.Deferred();
@@ -397,9 +290,6 @@ function report_delivery_baco(reporting){
       return defer;
     },
 
-
-
-
     /*====================================================================
         UPDATE SELECTIONS
     ====================================================================*/
@@ -447,16 +337,23 @@ function report_delivery_baco(reporting){
       }
     },
 
-
-    updatePeriodSelections: function() {
+    updateUsers: function() {
       var self = this;
-      var period = self.$el.find('#current-period').val();
-      if (period != 9999999) {
-        self.$el.find('#current-date').val(9999999);
-        self.$el.find('#current-date').prop('disabled', 'disabled');
-        self.$el.find('.datepicker').css('display', 'none');
+      var store = self.$el.find('#current-store').val();
+      if (store != 9999999) {
+        var user = self.$el.find('#current-user').empty();
+        self.$el.find('#current-user').append('<option value="9999999">Todos los usuarios</option>');
+        _.each(self.ResUser, function(item) {
+          if (parseFloat(store) == item.store_id[0]) {
+            self.$el.find('#current-user').append('<option value="' + item.id + '">' + item.name + '</option>');
+          }
+        });
       } else {
-        self.$el.find('#current-date').prop('disabled', false);
+        var user = self.$el.find('#current-user').empty();
+        self.$el.find('#current-user').append('<option value="9999999">Todos los usuarios</option>');
+        _.each(self.ResUser, function(item) {
+          self.$el.find('#current-user').append('<option value="' + item.id + '">' + item.name + '</option>');
+        });
       }
     },
 
@@ -487,18 +384,6 @@ function report_delivery_baco(reporting){
       })
     },
 
-    getResUser: function(id) {
-      var self = this;
-      var store = self.$el.find('#current-store').val();
-      var content = self.ResUser;
-
-      if(store && store != 9999999){
-              content = _.flatten(_.filter(content,function (item) {
-                  return item.store_id[0] == store;
-              }));
-          }
-          return content;
-    },
 
     getDelivery: function(type, store) {
       var self = this;
@@ -509,9 +394,6 @@ function report_delivery_baco(reporting){
       })
     },
 
-
-
-
     /*====================================================================
         BUILD
     ====================================================================*/
@@ -526,14 +408,9 @@ function report_delivery_baco(reporting){
       } else {
         var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
       };
-      /*
-      ==========================================
-          RECORRER PRODUCTOS
-      ==========================================
-      */
-      var ResUser = self.getResUser();
-      _.each(ResUser, function(i) {
 
+      var ResUser = self.ResUser;
+      _.each(ResUser, function(i) {
 
         var suma_local = 0;
         var suma_envio = 0;
@@ -558,8 +435,6 @@ function report_delivery_baco(reporting){
         local_amount = suma_local * local_delivery_amount[0];
         envio_amount = suma_envio * envio_delivery_amount[0];
 
-        console.log(local_amount);
-
         data.push({
           user : i.name,
           suma_local : suma_local,
@@ -575,28 +450,25 @@ function report_delivery_baco(reporting){
           thousands_separator: CurrencyBase.thousands_separator,
           decimal_separator: CurrencyBase.decimal_separator,
         });
-  })
-
-
-
-  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();
+      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;
-             self.rowsData = rowsTable;
-             var table = this.$el.find('#table');
-             table.bootstrapTable('load', rowsTable);
-         },
+      var self = this;
+      self.rowsData = rowsTable;
+      var table = this.$el.find('#table');
+      table.bootstrapTable('load', rowsTable);
+    },
 
     /*====================================================================
         PRINT PDF
@@ -619,9 +491,6 @@ function report_delivery_baco(reporting){
       var column = table.bootstrapTable('getVisibleColumns');
       var row = table.bootstrapTable('getData');
 
-
-      // impresion por categorias
-
       if (action === 'pdf') {
         var suma_local = localFormatter(row);
         var suma_envio = envioFormatter(row);
@@ -699,6 +568,7 @@ function report_delivery_baco(reporting){
       var self = this;
       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 period = self.$el.find('#current-period').val();
 
       var filter = [];
@@ -721,6 +591,16 @@ function report_delivery_baco(reporting){
         });
       };
 
+      if (user && user != 9999999) {
+        var ResUser = _.filter(self.ResUser, function(item) {
+          return item.id == user;
+        });
+        filter.push({
+          title: 'Usuario',
+          value: ResUser[0].name,
+        });
+      };
+
       if (period && period != 9999999) {
         var AccountPeriod = _.filter(self.AccountPeriod, function(item) {
           return item.id == period;

+ 5 - 1
static/src/reports/report_delivery_baco.xml

@@ -16,7 +16,11 @@
                         <select id="current-store" class="form-control form-control-sm">
                         </select>
                     </div>
-
+                    <div class="col-lg-3 user filter-style">
+                        <label>Usuario</label>
+                        <select id="current-user" class="form-control form-control-sm">
+                        </select>
+                    </div>
                     <div class="col-lg-3 filter-style">
                         <label>Periodo</label>
                         <select id="current-period" class="form-control form-control-sm">