def on_changed(self, selection): """Método que captura la señal del TreeView y carga los productos del cliente. :param selection: la seleccion en el TreeView. :return: Ninguno. """ (self.model, self.iter) = selection.get_selected() self.productos.clear() productos = SQLiteMetodos.selectProductos(self.model[self.iter][0]) for producto in productos: self.productos.append([ producto[0], producto[1], producto[2], str(producto[3]) + " €/ud", producto[4] ]) self.modelProductos.clear() for elemento in self.productos: self.modelProductos.append(elemento) if (self.auxiliar): for i in range(len(self.columProductos)): celda = Gtk.CellRendererText() self.columnaP = Gtk.TreeViewColumn(self.columProductos[i], celda, text=i) self.vistaProductos.append_column(self.columnaP) self.auxiliar = False
def on_Factura_clicked(self, widget): """Metodo que crea una factura. :param widget: Widget botón. :return: Ninguno. """ current_work_directory = os.getcwd( ) # Return a string representing the current working directory. dataC = [] clientes = SQLiteMetodos.selectClientesPorDni(self.model[self.iter][0]) for cliente in clientes: dataC.append(['Datos Cliente ', '', '', '', '']) dataC.append(['Dni: ', cliente[0], '', '', '']) dataC.append(['Nombre: ', cliente[1], '', '', '']) dataC.append(['Apellidos: ', cliente[2], '', '', '']) dataC.append(['Sexo: ', cliente[3], '', '', '']) dataC.append(['Direccion: ', cliente[4], '', '', '']) dataC.append(['Teléfono: ', cliente[5], '', '', '']) dataC.append(['', '', '', '', '']) precioFinal = 0.0 dataP = [] productos = SQLiteMetodos.selectProductos(self.model[self.iter][0]) try: dataP.append(["Id Producto", "Nombre", "Precio", "Cantidad"]) for producto in productos: dataP.append([ producto[0], producto[2], str(producto[3]) + " €/ud", producto[4] ]) precioFinal = precioFinal + (producto[3] * producto[4]) dataP.append(['', '', 'TOTAL:', str(precioFinal) + " €"]) rowNumb = len(dataP) # GENERAR PDF fileName = 'Factura' + dataC[1][1] + '.pdf' pdf = SimpleDocTemplate(current_work_directory + "/" + fileName, pagesize=letter) table = Table(dataC, colWidths=80, rowHeights=30) table.setStyle( TableStyle([ ('TEXTCOLOR', (0, 0), (0, -1), colors.darkred), ('ALIGN', (0, 0), (0, -1), 'LEFT'), ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ])) table2 = Table(dataP, colWidths=80, rowHeights=30) table2.getSpaceBefore() table2.setStyle( TableStyle([ ('TEXTCOLOR', (0, 0), (3, 0), colors.darkred), ('TEXTCOLOR', (0, rowNumb - 1), (3, rowNumb - 1), colors.darkred), ('ALIGN', (0, 0), (0, -1), 'LEFT'), ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ('ALIGN', (0, 0), (-1, -1), 'CENTER'), ('BOX', (0, 0), (-1, rowNumb - 2), 1, colors.black), ('INNERGRID', (0, 0), (-1, rowNumb - 2), 0.5, colors.grey) ])) elementos = [] elementos.append(table) elementos.append(table2) pdf.build(elementos) wb.open_new(current_work_directory + "/" + fileName) except IndexError as e: print('No se puede generar la factura.')