From e1828a8c80493d5d420ef7e158e03e8ab1f39838 Mon Sep 17 00:00:00 2001 From: sinergia Date: Fri, 18 Oct 2024 22:50:21 -0500 Subject: [PATCH] Feat(WIP): Se agrega soporte para generacion de QR's --- __init__.py | 1 + qr_generator.py | 23 +++++++++++++++++++++++ test/__init__.py | 0 test/fixtures/__init__.py | 0 test/fixtures/bill.json | 33 +++++++++++++++++++++++++++++++++ test/test_codigo_qr.png | Bin 0 -> 555 bytes test/test_generate_qr.py | 12 ++++++++++++ test/test_main.py | 25 +++++++++++++++++++++++++ 8 files changed, 94 insertions(+) create mode 100644 __init__.py create mode 100644 qr_generator.py create mode 100644 test/__init__.py create mode 100644 test/fixtures/__init__.py create mode 100644 test/fixtures/bill.json create mode 100644 test/test_codigo_qr.png create mode 100644 test/test_generate_qr.py create mode 100644 test/test_main.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ + diff --git a/qr_generator.py b/qr_generator.py new file mode 100644 index 0000000..e552c72 --- /dev/null +++ b/qr_generator.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +import qrcode + + +class QRCodeGenerator: + """Qr Generato""" + + def __init__(self, url): + self.url = url + + def generate_qr(self, filename="codigo_qr.png"): + """Genera un código QR a partir de la URL y lo guarda en un archivo.""" + qr = qrcode.QRCode( + version=1, + error_correction=qrcode.constants.ERROR_CORRECT_L, + box_size=10, + border=4, + ) + qr.add_data(self.url) + qr.make(fit=True) + img = qr.make_image(fill_color="black", back_color="white") + img.save(filename) + return filename diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/__init__.py b/test/fixtures/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/bill.json b/test/fixtures/bill.json new file mode 100644 index 0000000..5025886 --- /dev/null +++ b/test/fixtures/bill.json @@ -0,0 +1,33 @@ +{"shop_name": "SE", + "shop_address": "Calle Arriba 1234", + "fe_cufe": "https://catalogo-vpfe.dian.gov.co/document/searchqr?documentkey=936ef10e23f9fbae2d2c70869050b907b7af55a7d2c80a9f2e906450a8f98b20a88f7e4219fd0d02962f6e639b29ba20", + "invoice": { + "invoice_number": "FPES2068", + "resolution": { + "resolution_number": "18764072418755", + "resolution_prefix": "FPES", + "valid_date_time_from": "2024-06-06", + "valid_date_time_to": "2026-06-06", + "from_number": 1, "to_number": 30000} + }, "party": "00-Consumidor Final", + "tax_identifier_type": "NIT", + "tax_identifier_code": "222222222", + "address": "Dg 74A #C-2-56", "city": "Medellín", + "zone": "CHIMENEA (CH)", + "table": "CH1", + "lines": [ + {"type": "line", "product": "Club negra", "quantity": 1.0, "uom": "u", "unit_price": "9800.00", "taxes": "8.00%"}, + {"type": "line", "product": "Club roja", "quantity": 1.0, "uom": "u", "unit_price": "9800.00", "taxes": "8.00%"}, + {"type": "line", "product": "Aguila ligth", "quantity": 1.0, "uom": "u", "unit_price": "8600.00", "taxes": "8.00%"}, + {"type": "line", "product": "Propinas", "quantity": 1.0, "uom": "u", "unit_price": "27333.00", "taxes": null}], + "total_discount": "0.00", + "untaxed_amount": "300666.30", + "tax_amount": "21866.67", + "total_tip": "10000", + "total": "322532.97", + "state": "CUENTA FINAL", + "payments": [ + {"statement": "Transferencia TPV", "amount": "222532.00"}, + {"statement": "Efectivo TPV", "amount": "100000.97"} + ] +} diff --git a/test/test_codigo_qr.png b/test/test_codigo_qr.png new file mode 100644 index 0000000000000000000000000000000000000000..84005c0aa594d32b7e361b9139abd9a5ca3e1a0a GIT binary patch literal 555 zcmV+`0@VG9P)00Bw?00000Q&KCa0005(<%OIL=lQ6)yp4Y>MBOgK>WWj@}hF z-eNfkrLlIN+*>C>+2*4hg3VgSGLo{_t@EL?l|yi7Ga9B)7PAhle}w=?{~fiLF?B$j zgT+h8OVg?S3`+f5?Li%`)zP){l*5`bh=1O*LBQhpUhmF_YjqTTjm^b4t_98O)~V3V z>^NRRooY>s@vPrnfTNF~*V!@5CXKUQdl|0~;OHZ0ogHtQPRYz*GW&+^Bf!yT(DWgh zb@g_z*Wp?nU9y!*acThO^;?Zb tq;A|-fTItf=Kor7)KNzrb@V?%{{l6GFZm+p9$x?e002ovPDHLkV1m;p1vUTx literal 0 HcmV?d00001 diff --git a/test/test_generate_qr.py b/test/test_generate_qr.py new file mode 100644 index 0000000..d510d06 --- /dev/null +++ b/test/test_generate_qr.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +import os +import pytest +from ..qr_generator import QRCodeGenerator + + +def test_generate_qr(): + url = "https://www.gnu.org/" + qr_generator = QRCodeGenerator(url) + filename = qr_generator.generate_qr("test_codigo_qr.png") + assert os.path.exists(filename) + os.remove(filename) diff --git a/test/test_main.py b/test/test_main.py new file mode 100644 index 0000000..9943d3e --- /dev/null +++ b/test/test_main.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +from fastapi.testclient import TestClient +from ..api import app +import json + +client = TestClient(app) + + +def load_json(file_path): + with open(file_path, 'r') as filejson: + return json.load(filejson) + +def test_print_bill(): + test_info = { + "content": str( + json.dumps( + load_json('fixtures/bill.json') + )), + "ip_printer": "192.168.1.100", + "user_name": "Juan" + } + + response = client.post("/print_bill", json=test_info) + assert response.status_code == 200 + assert response.content.decode() == "!Impresion Realizada!"