|
@@ -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()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ])
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+}
|