|
@@ -0,0 +1,389 @@
|
|
|
+function report_stock_original (reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var instance = openerp;
|
|
|
+
|
|
|
+ reporting.ReportStockOriginalWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportStockOriginal',
|
|
|
+ stockLocation: [],
|
|
|
+ stockQuant: [],
|
|
|
+ productProduct : [],
|
|
|
+ rowsData: [],
|
|
|
+ content: [],
|
|
|
+ newStock: [],
|
|
|
+
|
|
|
+ events : {
|
|
|
+ 'change #current-location' : 'factSearch',
|
|
|
+ 'change #current-category' : 'factSearch',
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'click-row.bs.table #table ' : 'clickAnalysisDetail',
|
|
|
+ },
|
|
|
+ init : function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+ start : function(){
|
|
|
+ var self = this;
|
|
|
+ var dato=[];
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable({data : self.rowsData});
|
|
|
+ self.submitForm();
|
|
|
+ },
|
|
|
+ valorNull:function(dato){
|
|
|
+ var valor ="";
|
|
|
+ if (dato){
|
|
|
+ valor=dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+ clickAnalysisDetail: function(e, row, $element,field){
|
|
|
+ if (field == 'product'){
|
|
|
+ this.do_action({
|
|
|
+ name:"Variantes de Producto",
|
|
|
+ type: 'ir.actions.act_window',
|
|
|
+ res_model: "product.product",
|
|
|
+ views: [[false,'form']],
|
|
|
+ target: 'new',
|
|
|
+ domain: [['id', '=',row.id ]],
|
|
|
+ context: {},
|
|
|
+ flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
+ res_id: row.id,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ e.stopImmediatePropagation();
|
|
|
+ },
|
|
|
+ submitForm: function(){
|
|
|
+ var self = this;
|
|
|
+ self.fecthStockLocation().then(function(StockLocation){
|
|
|
+ self.StockLocation=StockLocation;
|
|
|
+ return StockLocation;
|
|
|
+ }).then(function(StockLocation){
|
|
|
+ self.$el.find('#current-location').append('<option value="9999999">Todas las Ubicación.</option>');
|
|
|
+ _.each(StockLocation,function(item){
|
|
|
+ self.$el.find('#current-location').append('<option value="' + item.id + '">' + item.location_id[1]+" / "+item.name + '</option>');
|
|
|
+ });
|
|
|
+ return self.fecthStockQuant();
|
|
|
+ }).then(function(StockQuant){
|
|
|
+ self.StockQuant = StockQuant;
|
|
|
+ return self.fecthProductProduct(StockQuant);
|
|
|
+ }).then(function(productProduct){
|
|
|
+ self.productProduct = productProduct;
|
|
|
+ return self.fecthProductCategory();
|
|
|
+ }).then(function(ProductCategory){
|
|
|
+ self.ProductCategory = ProductCategory;
|
|
|
+ self.$el.find('#current-category').append('<option value="9999999">Todos las categorias</option>');
|
|
|
+ _.each(ProductCategory, function (item) {
|
|
|
+ self.$el.find('#current-category').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ self.searchProduct();
|
|
|
+ return self.BuildTable(self.StockQuant, self.StockLocation);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fecthStockLocation : function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var location = new instance.web.Model('stock.location');
|
|
|
+ var fields = ['id', 'name', 'company_id', 'location_id'];
|
|
|
+ var domain =[['active', '=', true],['usage', '=', 'internal']];
|
|
|
+ location.query(fields).filter(domain).order_by('id').all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ })
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ fecthStockQuant : function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var location = _.flatten(_.map(self.StockLocation,function(item){
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ var company_id =(_.map(self.StockLocation, function(item){
|
|
|
+ return item.company_id[0];
|
|
|
+ })).shift();
|
|
|
+ var quant = new instance.web.Model('stock.quant');
|
|
|
+ var fields = ['id', 'product_id', 'qty', 'cost','location_id'];
|
|
|
+ var domain =[['company_id', '=', company_id],['location_id', 'in',location]];
|
|
|
+ quant.query(fields).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ })
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ fecthProductProduct: function(quant){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var ids = _.flatten(_.map(quant, function (item) {
|
|
|
+ return item.product_id[0];
|
|
|
+ }));
|
|
|
+ var fields = ['id','name','name_template', 'standard_price','type','attribute_value_ids', 'lst_price','ean13','categ_id','attribute_str'];
|
|
|
+ var productProduct = new instance.web.Model('product.product');
|
|
|
+ productProduct.query(fields).filter([['id', 'in', ids]]).all().then(function (results) {
|
|
|
+ defer.resolve(results)
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+ fecthProductCategory: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name'];
|
|
|
+ var ProductCategory = new instance.web.Model('product.category');
|
|
|
+ ProductCategory.query(fields).filter([['type', '=', 'normal']]).all().then(function (results) {
|
|
|
+ defer.resolve(results)
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ getProdcutoProduct: function(productProduct, StockQuant){
|
|
|
+ var self = this;
|
|
|
+ var product_ids= _.flatten(_.map(StockQuant,function(map){
|
|
|
+ return map.product_id[0];
|
|
|
+ }));
|
|
|
+
|
|
|
+ return _.filter(productProduct,function(prod){return _.contains(product_ids, prod.id)});
|
|
|
+ },
|
|
|
+ getStockQuant: function(product_id, quantObjs){
|
|
|
+ var self = this;
|
|
|
+ var quantProduct = quantObjs;
|
|
|
+ if (product_id){
|
|
|
+ quantProduct = _.filter(quantProduct, function(item){
|
|
|
+ return item.product_id[0] == product_id;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return quantProduct;
|
|
|
+ },
|
|
|
+
|
|
|
+ searchProduct: function () {
|
|
|
+ var self = this;
|
|
|
+ var results = self.productProduct;
|
|
|
+ results = _.map(results, function (item) {
|
|
|
+ return {
|
|
|
+ label: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' + self.valorNull(item.attribute_str) + ' ) ' ,
|
|
|
+ value: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' + self.valorNull(item.attribute_str) + ' ) '
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.$('#product').autocomplete({
|
|
|
+ source: results,
|
|
|
+ minLength:0,
|
|
|
+ search: function(event, ui) {
|
|
|
+ if (!(self.$('#product').val())){
|
|
|
+ self.factSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ close: function( event, ui ) {
|
|
|
+ self.factSearch();
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.factSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ BuildTable : function(StockQuant,StockLocation){
|
|
|
+ var self = this;
|
|
|
+ console.log(self);
|
|
|
+ var data=[];
|
|
|
+ var stock=[];
|
|
|
+ var itemLocation;
|
|
|
+ var itemProduct;
|
|
|
+ var itemQuant;
|
|
|
+ var ProductProduct;
|
|
|
+ var product;
|
|
|
+ var quantity = 0;
|
|
|
+ var total=0;
|
|
|
+ var cat = 0;
|
|
|
+ var quant;
|
|
|
+ for (var i = 0; i < StockLocation.length; i++) {
|
|
|
+ itemLocation = StockLocation[i];
|
|
|
+ ProductProduct = self.getProdcutoProduct(self.productProduct, self.StockQuant, itemLocation.id);
|
|
|
+ // console.log(ProductProduct);
|
|
|
+ for (var f = 0; f < ProductProduct.length; f++) {
|
|
|
+ itemProduct = ProductProduct[f];
|
|
|
+ //console.log(itemProduct);
|
|
|
+ itemQuant = self.getQuantProduct(itemLocation.id, itemProduct.id, StockQuant);
|
|
|
+ // console.log(itemQuant);
|
|
|
+ // if (itemQuant.length = 0){
|
|
|
+ // itemQuant={};
|
|
|
+ // console.log(itemProduct);
|
|
|
+ // itemQuant.qty=0;
|
|
|
+ // product = itemQuant.shift();
|
|
|
+ // total = parseInt(quantity * itemProduct.standard_price);
|
|
|
+ // data.push({
|
|
|
+ // id : product.product_id[0],
|
|
|
+ // product : product.product_id[1],
|
|
|
+ // ean13 : self.valorNull(itemProduct.ean13),
|
|
|
+ // category_name : itemProduct.categ_id[1],
|
|
|
+ // qty : accounting.formatNumber(quantity,2, ".", ","),
|
|
|
+ // standard_price : accounting.formatNumber(itemProduct.standard_price,0, ".", ","),
|
|
|
+ // lst_price : accounting.formatNumber(itemProduct.lst_price,0, ".", ","),
|
|
|
+ // valuation: accounting.formatNumber(total,0,".",","),
|
|
|
+ // category_id : itemProduct.categ_id[0],
|
|
|
+ // location_id : product.location_id[0],
|
|
|
+ // location_name: product.location_id[1],
|
|
|
+ // total : total
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ if (itemQuant.length > 0){
|
|
|
+ quantity = _.reduce(_.map(itemQuant,function(item){
|
|
|
+ return item.qty;
|
|
|
+ }),function(mamo, num){
|
|
|
+ return mamo + num;
|
|
|
+ },0);
|
|
|
+ product = itemQuant.shift();
|
|
|
+ total = parseInt(quantity * itemProduct.standard_price);
|
|
|
+ data.push({
|
|
|
+ id : product.product_id[0],
|
|
|
+ product : product.product_id[1],
|
|
|
+ ean13 : self.valorNull(itemProduct.ean13),
|
|
|
+ category_name : itemProduct.categ_id[1],
|
|
|
+ qty : accounting.formatNumber(quantity,2, ".", ","),
|
|
|
+ standard_price : accounting.formatNumber(itemProduct.standard_price,0, ".", ","),
|
|
|
+ lst_price : accounting.formatNumber(itemProduct.lst_price,0, ".", ","),
|
|
|
+ valuation: accounting.formatNumber(total,0,".",","),
|
|
|
+ category_id : itemProduct.categ_id[0],
|
|
|
+ location_id : product.location_id[0],
|
|
|
+ location_name: product.location_id[1],
|
|
|
+ total : total
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.content = data;
|
|
|
+ self.loadTable(data);
|
|
|
+ },
|
|
|
+
|
|
|
+ // Obtener Qaunt por productos
|
|
|
+ getQuantProduct: function(location_id, product_id, quantObjs){
|
|
|
+ var self = this;
|
|
|
+ var quantProdcut = quantObjs;
|
|
|
+ if (location_id){
|
|
|
+ quantProdcut = _.filter(quantProdcut, function(item){
|
|
|
+ return item.location_id[0] === location_id;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (product_id){
|
|
|
+ quantProdcut = _.filter(quantProdcut, function(item){
|
|
|
+ return item.product_id[0] === product_id;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return quantProdcut;
|
|
|
+ },
|
|
|
+
|
|
|
+ factSearch: function(){
|
|
|
+ var self = this;
|
|
|
+ var category = this.$el.find('#current-category').val();
|
|
|
+ var product= this.$el.find('#product').val().split('-');
|
|
|
+ var location =this.$el.find('#current-location').val();
|
|
|
+ var content = self.content;
|
|
|
+ // console.log(content);
|
|
|
+ if(category != 9999999){
|
|
|
+ content = _.filter(content,function(inv){
|
|
|
+ return inv.category_id == category;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (location != 9999999){
|
|
|
+ content=_.filter(content, function (inv){
|
|
|
+ return inv.location_id == location;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (product != ""){
|
|
|
+ content = _.filter(content, function(inv){
|
|
|
+ return inv.id == product[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ self.loadTable(content)
|
|
|
+ // self.BuildTable(quantObjs,locationObjs)
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ loadTable:function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ self.rowsData = rowsTable;
|
|
|
+ var table = self.$el.find('#table');
|
|
|
+ table.bootstrapTable('load' ,rowsTable);
|
|
|
+ },
|
|
|
+ getObjectPdf: function(){
|
|
|
+ var self = this;
|
|
|
+ var rows=[];
|
|
|
+ var rows = self.rowsData;
|
|
|
+ var total = _.reduce(_.map(rows,function(map){
|
|
|
+ return(map.total);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+ if (rows.length > 0){
|
|
|
+ rows.push({
|
|
|
+ product: "Totales ",
|
|
|
+ valuation: accounting.formatNumber(total,0,".",","),
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return rows;
|
|
|
+ },
|
|
|
+ clickOnAction: function (e) {
|
|
|
+ var self = this;
|
|
|
+ var rowsNew;
|
|
|
+ var action = self.$el.find(e.target).val();
|
|
|
+ var table = self.$el.find("#table");
|
|
|
+ var data2 = table.bootstrapTable('getVisibleColumns');
|
|
|
+ var getColumns=[];
|
|
|
+ var rows=[];
|
|
|
+ rowsNew = self.getObjectPdf();
|
|
|
+ if (action === 'pdf') {
|
|
|
+ var dataNEW = _.map(data2, function (val){
|
|
|
+ return val.field;
|
|
|
+ });
|
|
|
+ _.each(rowsNew,function (item){
|
|
|
+ rows.push(_.pick(item, dataNEW));
|
|
|
+ });
|
|
|
+ // Obtener los nombre de la Cabezera
|
|
|
+ _.each(_.map(data2,function(val){
|
|
|
+ return val;
|
|
|
+ }), function(item){
|
|
|
+ getColumns.push([{
|
|
|
+ title: item.title,
|
|
|
+ dataKey: item.field
|
|
|
+ }]);
|
|
|
+ });
|
|
|
+ this.drawPDF(_.flatten(getColumns),rows);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ drawPDF:function(getColumns,rows){
|
|
|
+ var self = this;
|
|
|
+ var fechaActu= new Date();
|
|
|
+ var location = this.sucDescrip = this.$el.find('#current-location option:selected').text();
|
|
|
+ var totalPagesExp = "{total_pages_count_string}";
|
|
|
+ var pdfDoc = new jsPDF();
|
|
|
+ pdfDoc.autoTable(getColumns, rows, {
|
|
|
+ styles: { overflow: 'linebreak', fontSize:8 , columnWidth: 'wrap'},
|
|
|
+ columnStyles:{
|
|
|
+ product :{columnWidth: '8px'},
|
|
|
+ qty : {halign:'center'},
|
|
|
+ standard_price : {halign:'right'},
|
|
|
+ lst_price : {halign:'right'},
|
|
|
+ valuation : {halign:'right'},
|
|
|
+ category_name :{columnWidth: '8px'},
|
|
|
+ location_name :{columnWidth: '8px'},
|
|
|
+ },
|
|
|
+ margin: { top: 16, horizontal: 7},
|
|
|
+ addPageContent: function (data) {
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Listado de productos', data.settings.margin.left, 10);
|
|
|
+ // FOOTER
|
|
|
+ var str = "Pagina " + data.pageCount;
|
|
|
+ if (typeof pdfDoc.putTotalPages === 'function') {
|
|
|
+ str = str + " de " + totalPagesExp;
|
|
|
+ // +"\n Día de Expedición "+fechaActu.getDate()+"/"+fechaActu.getMonth()+"/"+fechaActu.getFullYear();
|
|
|
+ }
|
|
|
+ pdfDoc.setFontSize(9);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(str, data.settings.margin.left, pdfDoc.internal.pageSize.height - 5);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (typeof pdfDoc.putTotalPages === 'function') {
|
|
|
+ pdfDoc.putTotalPages(totalPagesExp);
|
|
|
+ }
|
|
|
+ pdfDoc.save('Listado de productos.pdf');
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|