Feat(WIP): Se agrega soporte para generacion de QR's
This commit is contained in:
parent
674209a994
commit
e1828a8c80
1
__init__.py
Normal file
1
__init__.py
Normal file
@ -0,0 +1 @@
|
||||
|
23
qr_generator.py
Normal file
23
qr_generator.py
Normal file
@ -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
|
0
test/__init__.py
Normal file
0
test/__init__.py
Normal file
0
test/fixtures/__init__.py
vendored
Normal file
0
test/fixtures/__init__.py
vendored
Normal file
33
test/fixtures/bill.json
vendored
Normal file
33
test/fixtures/bill.json
vendored
Normal file
@ -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"}
|
||||
]
|
||||
}
|
BIN
test/test_codigo_qr.png
Normal file
BIN
test/test_codigo_qr.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 555 B |
12
test/test_generate_qr.py
Normal file
12
test/test_generate_qr.py
Normal file
@ -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)
|
25
test/test_main.py
Normal file
25
test/test_main.py
Normal file
@ -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!"
|
Loading…
Reference in New Issue
Block a user