Пример #1
0
    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.')
    def on_buttonFactura_clicked(self, widget):
        """Metodo que crea una factura del cliente seeccionado en el treeview.

           :param widget: Widget botón.
           :return: No devuelve ningún parámetro.

        """
        # DATOS CLIENTE SELECCIONADO
        current_work_directory = os.getcwd(
        )  # Return a string representing the current working directory.
        dataC = []
        clientes = SQLiteMetodos.selectTablaClientesDni(
            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(['', '', '', '', ''])

            # PRODUCTOS DEL CLIENTE SELECCIONADO
            precioTotal = 0.0
            dataP = []
            productos = SQLiteMetodos.selectTablaProductos(
                self.model[self.iter][0])
            # Productos que pertenecen al cliente seleccionado
        try:
            dataP.append(["Id Producto", "Nombre", "Precio", "Cantidad"])
            for producto in productos:
                dataP.append([
                    producto[0], producto[2],
                    str(producto[3]) + " €/ud", producto[4]
                ])
                precioTotal = precioTotal + (producto[3] * producto[4])

            dataP.append(['', '', 'PRECIO TOTAL:', str(precioTotal) + " €"])
            rowNumb = len(dataP)

            # GENERAR PDF
            fileName = 'Factura' + dataC[1][1] + '.pdf'
            pdf = SimpleDocTemplate(current_work_directory + "/" + fileName,
                                    pagesize=letter)
            # DATOS CLIENTE

            table = Table(dataC, colWidths=80, rowHeights=30)
            table.setStyle(
                TableStyle([
                    ('TEXTCOLOR', (0, 0), (0, -1), colors.darkgreen),
                    ('ALIGN', (0, 0), (0, -1), 'LEFT'),
                    ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
                ]))

            # DATOS PRODUCTOS CLIENTE
            table2 = Table(dataP, colWidths=80, rowHeights=30)
            table2.getSpaceBefore()
            table2.setStyle(
                TableStyle([
                    ('TEXTCOLOR', (0, 0), (3, 0), colors.darkgreen),
                    ('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)
                ]))

            # Creación de las dtabla
            elementos = []
            elementos.append(table)
            elementos.append(table2)
            pdf.build(elementos)
            wb.open_new(current_work_directory + "/" + fileName)

        except IndexError as e:
            print('No hay productos para generar la factura.')