Example #1
0
 def test_interleaved2of5(self, tmp_path):
     pdf = FPDF()
     pdf.add_page()
     pdf.interleaved2of5("1337", x=65, y=50, w=4, h=20)
     pdf.set_font("courier", "B", size=36)
     pdf.text(x=80, y=80, txt="1337")
     assert_pdf_equal(pdf, HERE / "barcodes_interleaved2of5.pdf", tmp_path)
Example #2
0
 def test_interleaved2of5(self):
     pdf = FPDF()
     pdf.add_page()
     pdf.interleaved2of5("1337", x=65, y=50, w=4, h=20)
     pdf.set_font("courier", "B", size=36)
     pdf.text(x=80, y=80, txt="1337")
     assert_pdf_equal(self, pdf, "test_interleaved2of5.pdf")
def generarFacturaPdf(Factura, directorio, usuario):

    aleatorio = str(random.randint(0, 10000))
    now = datetime.now()

    # accedo a los datos de la factura
    bild = Factura
    c = bild.client
    totalFactura = 0
    date = bild.fecha
    d = bild.lineas
    codigo = bild.cod + aleatorio + strftime("%b") + str(now.year)
    enunciado = bild.head
    documentoDni = c.dni

    strftime("%b")

    pdf = FPDF()
    pdf.add_page(orientation='P')
    pdf.set_font('arial', '', 13.0)

    pdf.set_xy(105.0, 8.0)
    pdf.cell(ln=0, h=22.0, align='C', w=75.0, txt=enunciado, border=0)
    pdf.set_line_width(0.0)
    pdf.rect(15.0, 15.0, 170.0, 245.0)
    pdf.set_line_width(0.0)
    pdf.rect(95.0, 15.0, 10.0, 10.0)

    # descomentar para poner imagen
    # pdf.image("BikeLogo.png", 10.0, 10.0, type="png", w=13.0, h=13.0)
    # pdf.image("BikeLogo.png", x=None, y=None, w=0, h=0, type='png', link='')

    pdf.set_font('arial', 'B', 16.0)
    pdf.set_xy(95.0, 18.0)
    pdf.cell(ln=0, h=2.0, align='C', w=10.0, txt='X', border=0)
    pdf.set_font('arial', '', 8.0)
    pdf.set_xy(105.0, 21.0)
    pdf.cell(ln=0, h=4.0, align='C', w=75.0, txt='Original', border=0)
    pdf.set_font('arial', 'B', 7.0)
    pdf.set_xy(95.0, 21.5)
    pdf.cell(ln=0, h=4.5, align='C', w=10.0, txt='COD.00', border=0)
    pdf.set_line_width(0.0)
    pdf.line(100.0, 25.0, 100.0, 57.0)
    pdf.set_font('arial', 'B', 14.0)
    pdf.set_xy(125.0, 25.5)
    pdf.cell(ln=0, h=9.5, align='L', w=60.0, txt=codigo, border=0)
    pdf.set_xy(115.0, 27.5)
    pdf.cell(ln=0, h=5.5, align='L', w=10.0, txt='N\xba: ', border=0)
    pdf.set_font('arial', 'B', 12.0)
    pdf.set_xy(17.0, 32.5)

    # confeccion zona datos empresa
    pdf.cell(ln=0,
             h=5.0,
             align='L',
             w=98.0,
             txt='BICICLETAS EGIBIDE',
             border=0)
    pdf.set_xy(17.0, 38.5)
    pdf.cell(ln=0,
             h=5.0,
             align='L',
             w=98.0,
             txt='C/Arriaga, 5 - bajo',
             border=0)
    pdf.set_xy(17.0, 44.5)
    pdf.cell(ln=0,
             h=5.0,
             align='L',
             w=98.0,
             txt='01001 - Vitoria-Gasteiz',
             border=0)
    pdf.set_xy(17.0, 50.5)
    pdf.cell(ln=0, h=5.0, align='L', w=98.0, txt='CIF: B-0125693', border=0)

    pdf.set_font('arial', '', 12.0)
    pdf.set_xy(115.0, 33.0)
    pdf.cell(ln=0, h=7.0, align='L', w=60.0, txt='Fecha:', border=0)
    pdf.set_xy(135.0, 33.0)
    pdf.cell(ln=0, h=7.0, align='L', w=40.0, txt=date, border=0)
    pdf.set_line_width(0.0)
    pdf.line(15.0, 57.0, 185.0, 57.0)
    pdf.set_font('arial', '', 10.0)
    pdf.set_xy(17.0, 59.0)
    pdf.cell(ln=0, h=6.0, align='L', w=13.0, txt='Sr.(s):', border=0)
    pdf.set_xy(35.0, 59.0)
    pdf.cell(ln=0, h=6.0, align='L', w=140.0, txt=c.nameClient, border=0)
    pdf.set_xy(17.0, 64.0)
    pdf.cell(ln=0, h=6.0, align='L', w=18.0, txt='Mail:', border=0)
    pdf.set_xy(35.0, 64.0)
    pdf.cell(ln=0, h=6.0, align='L', w=125.0, txt=c.email, border=0)
    pdf.set_xy(17.0, 69.0)
    pdf.cell(ln=0, h=6.0, align='L', w=18.0, txt='Tel\xe9fono:', border=0)
    pdf.set_xy(35.0, 69.0)
    pdf.cell(ln=0, h=6.0, align='L', w=80.0, txt=c.telefono, border=0)
    pdf.set_xy(115.0, 69.0)
    # pdf.cell(ln=0, h=6.0, align='L', w=18.0, txt='Localidad:', border=0)
    # pdf.set_xy(133.0, 69.0)
    # pdf.cell(ln=0, h=6.0, align='L', w=42.0, txt='Vitoria', border=0)
    pdf.set_line_width(0.0)
    pdf.line(15.0, 77.0, 185.0, 77.0)
    pdf.set_xy(17.0, 80.0)
    pdf.cell(ln=0, h=5.0, align='L', w=15.0, txt='', border=0)
    pdf.set_xy(35.0, 80.0)
    pdf.cell(ln=0, h=5.0, align='L', w=70.0, txt='', border=0)
    pdf.set_xy(115.0, 80.0)
    pdf.cell(ln=0, h=5.0, align='L', w=20.0, txt='', border=0)
    pdf.set_xy(135.0, 80.0)
    pdf.cell(ln=0, h=5.0, align='L', w=40.0, txt='', border=0)
    pdf.set_line_width(0.0)
    pdf.line(15.0, 88.0, 185.0, 88.0)
    pdf.set_xy(17.0, 90.0)
    pdf.cell(ln=0,
             h=5.0,
             align='L',
             w=48.0,
             txt='Fecha de Vencimiento Pago:',
             border=0)
    pdf.set_xy(65.0, 90.0)
    pdf.cell(ln=0, h=5.0, align='L', w=20.0, txt='', border=0)
    pdf.set_xy(92.0, 90.0)
    pdf.cell(ln=0,
             h=5.0,
             align='L',
             w=43.0,
             txt='Per\xedodo Facturado',
             border=0)
    pdf.set_xy(125.0, 90.0)
    pdf.cell(ln=0, h=5.0, align='L', w=20.0, txt=date, border=0)
    pdf.set_xy(150.0, 90.0)
    pdf.cell(ln=0, h=5.0, align='L', w=20.0, txt='', border=0)
    pdf.set_line_width(0.0)
    pdf.line(15.0, 95.0, 185.0, 95.0)
    pdf.set_line_width(0.0)
    pdf.line(155.0, 95.0, 155.0, 230.0)
    pdf.set_xy(20.0, 97.0)
    pdf.cell(ln=0, h=5.0, align='L', w=125.0, txt='Descripci\xf3n', border=0)
    pdf.set_xy(160.0, 97.0)
    pdf.cell(ln=0, h=5.0, align='R', w=20.0, txt='Importe', border=0)
    pdf.set_line_width(0.0)
    pdf.line(15.0, 102.0, 185.0, 102.0)

    posicion = 103.0

    posicionador = 1
    for i in d:
        # linea 1 factura posicion
        pdf.set_xy(20.0, posicion)
        pdf.cell(ln=0, h=7.0, align='L', w=125.0, txt=i[0], border=0)

        pdf.set_xy(160.0, posicion)
        pdf.cell(ln=0, h=7.0, align='R', w=20.0, txt=str(i[1]), border=0)

        totalFactura = totalFactura + i[1]

        posicion = posicion + 4.0

    # linea 2 posicion
    # .set_xy(20.0, 108.0)
    # pdf.cell(ln=0, h=7.0, align='L', w=125.0, txt='articulo 2', border=0)
    # posiciono donde voy a escribir el importe
    # pdf.set_xy(160.0, 108.0)
    # pdf.cell(ln=0, h=7.0, align='R', w=20.0, txt='200,00', border=0)

    pdf.set_line_width(0.0)
    pdf.line(15.0, 230.0, 185.0, 230.0)
    pdf.set_xy(20.0, 233.0)
    pdf.cell(ln=0, h=5.0, align='L', w=95.0, txt='CAE N\xba', border=0)
    pdf.set_xy(45.0, 233.0)
    pdf.cell(ln=0, h=5.0, align='L', w=30.0, txt='01234567890', border=0)
    pdf.set_font('arial', '', 12.0)
    pdf.set_xy(105.0, 234.0)
    pdf.cell(ln=0, h=9.0, align='R', w=45.0, txt='IMPORTE NETO:', border=0)
    pdf.set_font('arial', 'B', 12.0)
    pdf.set_xy(145.0, 234.0)
    pdf.cell(ln=0, h=9.0, align='R', w=33.0, txt=str(totalFactura), border=0)
    pdf.set_font('arial', '', 10.0)
    pdf.set_xy(20.0, 238.0)
    pdf.cell(ln=0, h=5.0, align='L', w=95.0, txt='Fecha Vto. CAE:', border=0)
    pdf.set_xy(55.0, 238.0)
    pdf.cell(ln=0, h=5.0, align='L', w=30.0, txt='', border=0)
    pdf.set_font('arial', '', 12.0)
    pdf.set_xy(125.0, 241.0)
    pdf.cell(ln=0, h=9.0, align='R', w=25.0, txt='IVA 21%:', border=0)
    pdf.set_font('arial', 'B', 12.0)
    pdf.set_xy(145.0, 241.0)
    pdf.cell(ln=0, h=9.0, align='R', w=33.0, txt='21,00', border=0)
    pdf.interleaved2of5('012345678905', 20.0, 243.5, w=0.75)
    pdf.set_font('arial', 'B', 12.0)
    pdf.set_xy(105.0, 251.0)
    pdf.cell(ln=0,
             h=9.0,
             align='R',
             w=73.0,
             txt=str(totalFactura + totalFactura * 0.21),
             border=0)
    pdf.set_font('arial', '', 12.0)
    pdf.set_xy(125.0, 251.0)
    pdf.cell(ln=0, h=9.0, align='R', w=25.0, txt='Total:', border=0)
    pdf.set_line_width(0.0)
    pdf.rect(155.0, 252.0, 25.0, 7.0)
    pdf.set_font('arial', '', 10.0)
    pdf.set_xy(20.0, 253.0)
    pdf.cell(ln=0, h=7.0, align='L', w=120.0, txt='012345678905', border=0)

    # guardo el documento en la ruta indicada
    pdf.output(".\\" + directorio + "\\" + codigo + ".pdf", "F")

    # muestro en pdf el documento generado
    os.system(".\\" + directorio + "\\" + codigo + ".pdf")

    if bild.dep == "ve":
        # inserto la factura de venta en bd
        insertarFacturaVentaBD(date, codigo, documentoDni, usuario)

    elif bild.dep == "ta":

        insertarFacturaTallerBD(date, codigo, documentoDni, usuario)

    print("Creada correctamente  {}".format(codigo))
pdf.cell(ln=0, h=9.0, align='R', w=45.0, txt='Subtotal:', border=0)
pdf.set_font('arial', 'B', 12.0)
pdf.set_xy(145.0, 234.0)
pdf.cell(ln=0, h=9.0, align='R', w=33.0, txt='100,00', border=0)
pdf.set_font('arial', '', 10.0)
pdf.set_xy(20.0, 238.0)
pdf.cell(ln=0, h=5.0, align='L', w=95.0, txt='Fecha Vto. CAE:', border=0)
pdf.set_xy(55.0, 238.0)
pdf.cell(ln=0, h=5.0, align='L', w=30.0, txt='19/02/2009', border=0)
pdf.set_font('arial', '', 12.0)
pdf.set_xy(125.0, 241.0)
pdf.cell(ln=0, h=9.0, align='R', w=25.0, txt='VAT 21%:', border=0)
pdf.set_font('arial', 'B', 12.0)
pdf.set_xy(145.0, 241.0)
pdf.cell(ln=0, h=9.0, align='R', w=33.0, txt='21,00', border=0)
pdf.interleaved2of5('012345678905', 20.0, 243.5, w=0.75)
pdf.set_font('arial', 'B', 12.0)
pdf.set_xy(105.0, 251.0)
pdf.cell(ln=0, h=9.0, align='R', w=73.0, txt='121,00', border=0)
pdf.set_font('arial', '', 12.0)
pdf.set_xy(125.0, 251.0)
pdf.cell(ln=0, h=9.0, align='R', w=25.0, txt='Total:', border=0)
pdf.set_line_width(0.0)
pdf.rect(155.0, 252.0, 25.0, 7.0)
pdf.set_font('courier', '', 10.0)
pdf.set_xy(20.0, 253.0)
pdf.cell(ln=0, h=7.0, align='L', w=120.0, txt='012345678905', border=0)
pdf.output('./invoice.pdf', 'F')

import sys
if sys.platform.startswith("linux"):
pdf.cell(ln=0, h=9.0, align="R", w=45.0, txt="Subtotal:", border=0)
pdf.set_font("arial", "B", 12.0)
pdf.set_xy(145.0, 234.0)
pdf.cell(ln=0, h=9.0, align="R", w=33.0, txt="100,00", border=0)
pdf.set_font("arial", "", 10.0)
pdf.set_xy(20.0, 238.0)
pdf.cell(ln=0, h=5.0, align="L", w=95.0, txt="Fecha Vto. CAE:", border=0)
pdf.set_xy(55.0, 238.0)
pdf.cell(ln=0, h=5.0, align="L", w=30.0, txt="19/02/2009", border=0)
pdf.set_font("arial", "", 12.0)
pdf.set_xy(125.0, 241.0)
pdf.cell(ln=0, h=9.0, align="R", w=25.0, txt="VAT 21%:", border=0)
pdf.set_font("arial", "B", 12.0)
pdf.set_xy(145.0, 241.0)
pdf.cell(ln=0, h=9.0, align="R", w=33.0, txt="21,00", border=0)
pdf.interleaved2of5("012345678905", 20.0, 243.5, w=0.75)
pdf.set_font("arial", "B", 12.0)
pdf.set_xy(105.0, 251.0)
pdf.cell(ln=0, h=9.0, align="R", w=73.0, txt="121,00", border=0)
pdf.set_font("arial", "", 12.0)
pdf.set_xy(125.0, 251.0)
pdf.cell(ln=0, h=9.0, align="R", w=25.0, txt="Total:", border=0)
pdf.set_line_width(0.0)
pdf.rect(155.0, 252.0, 25.0, 7.0)
pdf.set_font("courier", "", 10.0)
pdf.set_xy(20.0, 253.0)
pdf.cell(ln=0, h=7.0, align="L", w=120.0, txt="012345678905", border=0)
pdf.output("./invoice.pdf", "F")


# import sys