Ver código fonte

commit print_clientes

sebas 7 anos atrás
commit
32769ed767
6 arquivos alterados com 122 adições e 0 exclusões
  1. 1 0
      __init__.py
  2. BIN
      __init__.pyc
  3. 11 0
      __openerp__.py
  4. BIN
      static/description/icon.png
  5. 101 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 Clientes",
+    'author': "Sebastian Penayo-Robert Gauto/Eiru Software",
+    'category': 'Tools',
+    'version': '0.1',
+    'depends': ['base'],
+    'data': [
+        'templates.xml',
+    ]
+}

BIN
static/description/icon.png


+ 101 - 0
static/src/main.js

@@ -0,0 +1,101 @@
+openerp.print_clientes = 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_clientes().then(function (clientes) {
+                // cuerpo del pdf
+                for (var i = 0; i < clientes.length; i++) {
+                    doc.push({
+                        name : self.valorNull(clientes[i].name),
+                        ruc : self.valorNull(clientes[i].ruc),
+                        mobile : self.valorNull(clientes[i].mobile),
+                        phone : self.valorNull(clientes[i].phone),
+                        email : self.valorNull(clientes[i].email)
+                    })
+                }
+                self.crear_pdf(doc);
+            });
+        },
+
+        obtener_clientes: 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 (clientes) {
+            var documento = new jsPDF();
+            var columns = [
+                     {title: "Nombre y Apellido"},
+                     {title: "RUC"},
+                     {title: "Celular"},
+                     {title: "Telefono"},
+                     {title: "Email"}
+            ];
+            documento.autoTable(columns, _.map(clientes, function (cliente) {
+                return _.values(cliente);
+            }), {
+                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 Clientes", 45, 30,'center');
+                }
+
+            });
+
+            documento.save('reporte_de_clientes_' + 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_customer !== 1) return
+
+                var self = this;
+
+                this.sidebar.add_items('print', [
+                    {
+                        label: 'Listado de Clientes',
+                        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_clientes.assets" name="Eiru Assets" inherit_id="web.assets_backend">
+            <xpath expr="." position="inside">
+                <script type="text/javascript" src="/print_clientes/static/src/main.js" />
+            </xpath>
+        </template>
+    </data>
+</openerp>