Explorar el Código

commit print_proveedores

sebas hace 7 años
commit
b8f167b1a9
Se han modificado 6 ficheros con 126 adiciones y 0 borrados
  1. 1 0
      __init__.py
  2. BIN
      __init__.pyc
  3. 11 0
      __openerp__.py
  4. BIN
      static/description/icon.png
  5. 105 0
      static/src/main.js
  6. 9 0
      templates.xml

+ 1 - 0
__init__.py

@@ -0,0 +1 @@
+# -*- coding: utf-8 -*-

BIN
__init__.pyc


+ 11 - 0
__openerp__.py

@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+{
+    'name': "Listado de Proveedores",
+    'author': "Sebastian Penayo-Robert Gauto/Eiru Software",
+    'category': 'Tools',
+    'version': '0.1',
+    'depends': ['base'],
+    'data': [
+        'templates.xml',
+    ]
+}

BIN
static/description/icon.png


+ 105 - 0
static/src/main.js

@@ -0,0 +1,105 @@
+openerp.print_proveedores = function (instance, local) {
+    "use strict";
+
+    local.MiniReporte = instance.Widget.extend({
+        fields: ['name', 'ruc', 'mobile', 'phone', 'email'],
+        init: function(parent, modelo, ids_seleccionados) {
+            this._super(parent);
+
+            this.modelo = modelo;
+            this.ids_seleccionados = ids_seleccionados;
+        },
+
+        start: function() {
+            var self = this;
+            var doc=[];
+
+            this.obtener_proveedores().then(function (proveedores) {
+
+                    // cuerpo del pdf
+                    for (var i = 0; i < proveedores.length; i++) {
+                        doc.push({
+                            name : self.valorNull(proveedores[i].name),
+                            ruc : self.valorNull(proveedores[i].ruc),
+                            mobile : self.valorNull(proveedores[i].mobile),
+                            phone : self.valorNull(proveedores[i].phone),
+                            email : self.valorNull(proveedores[i].email)
+                        })
+                    }
+                self.crear_pdf(doc);
+            });
+        },
+
+        obtener_proveedores: function () {
+            var Partner = new instance.web.Model('res.partner');
+            return Partner.query(this.fields).filter([['id', 'in', this.ids_seleccionados]]).all()
+        },
+
+        // Verificar si los Valores no son nulos
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+
+
+        crear_pdf: function (proveedores) {
+            var documento = new jsPDF();
+            // cabecera del pdf
+            var columns = [
+                     {title: "Nombre y Apellido"},
+                     {title: "RUC"},
+                     {title: "Celular"},
+                     {title: "Telefono"},
+                     {title: "Email"}
+            ];
+
+            documento.autoTable(columns, _.map(proveedores, function (proveedor) {
+                return _.values(proveedor);
+            }), {
+                styles: {overflow: 'linebreak', fontSize:8 },
+                columnStyles:{
+                        name : {columnWidth: '12px'},
+                        ruc : {columnWidth: '8px'},
+                        mobile : {columnWidth: '8px'},
+                        phone : {halign:'right',columnWidth: '8px'},
+                        email :{halign:'right',columnWidth: '8px'},
+                    },
+                margin: {top: 40},
+                addPageContent: function(data) {
+                documento.text("Listado de Proveedores", 45, 30,'center');
+                }
+
+            });
+
+            documento.save('reporte_de_proveedores_' + Date.now() + '.pdf');
+        }
+    })
+
+    if (instance.web && instance.web.ListView) {
+        instance.web.ListView.include({
+            do_show: function() {
+                this._super.apply(this, arguments);
+
+                if (this.model != 'res.partner' || this.dataset.context.search_default_supplier !== 1) return
+
+                var self = this;
+
+                this.sidebar.add_items('print', [
+                    {
+                        label: 'Listado de Proveedores',
+                        classname: 'oe_sidebar_print',
+                        callback: function () {
+                            var widget = new local.MiniReporte(self, self.model, self.get_selected_ids());
+                            widget.start()
+                        }
+                    }
+                ])
+
+            }
+
+        })
+    }
+}

+ 9 - 0
templates.xml

@@ -0,0 +1,9 @@
+<openerp>
+    <data>
+        <template id="print_proveedores.assets" name="Eiru Assets" inherit_id="web.assets_backend">
+            <xpath expr="." position="inside">
+                <script type="text/javascript" src="/print_proveedores/static/src/main.js" />
+            </xpath>
+        </template>
+    </data>
+</openerp>