diff --git a/InvenTree/InvenTree/static/css/inventree.css b/InvenTree/InvenTree/static/css/inventree.css index a0053e5f53..34c101e86d 100644 --- a/InvenTree/InvenTree/static/css/inventree.css +++ b/InvenTree/InvenTree/static/css/inventree.css @@ -125,6 +125,7 @@ .qr-container { width: 100%; align-content: center; + object-fit: fill; } .navbar-brand { diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index 9f7be3fce1..c5b439c0be 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -20,7 +20,7 @@ from stock.urls import stock_urls from build.urls import build_urls from order.urls import order_urls -from barcode.api import barcode_api_urls +from barcodes.api import barcode_api_urls from common.api import common_api_urls from part.api import part_api_urls, bom_api_urls from company.api import company_api_urls diff --git a/InvenTree/barcode/__init__.py b/InvenTree/barcodes/__init__.py similarity index 100% rename from InvenTree/barcode/__init__.py rename to InvenTree/barcodes/__init__.py diff --git a/InvenTree/barcode/api.py b/InvenTree/barcodes/api.py similarity index 99% rename from InvenTree/barcode/api.py rename to InvenTree/barcodes/api.py index f8a2c37329..d727f5a778 100644 --- a/InvenTree/barcode/api.py +++ b/InvenTree/barcodes/api.py @@ -12,7 +12,7 @@ from rest_framework.views import APIView from stock.models import StockItem from stock.serializers import StockItemSerializer -from barcode.barcode import load_barcode_plugins, hash_barcode +from barcodes.barcode import load_barcode_plugins, hash_barcode class BarcodeScan(APIView): diff --git a/InvenTree/barcode/barcode.py b/InvenTree/barcodes/barcode.py similarity index 98% rename from InvenTree/barcode/barcode.py rename to InvenTree/barcodes/barcode.py index 004182e0be..412065bf75 100644 --- a/InvenTree/barcode/barcode.py +++ b/InvenTree/barcodes/barcode.py @@ -5,7 +5,7 @@ import hashlib import logging from InvenTree import plugins as InvenTreePlugins -from barcode import plugins as BarcodePlugins +from barcodes import plugins as BarcodePlugins from stock.models import StockItem from stock.serializers import StockItemSerializer, LocationSerializer diff --git a/InvenTree/barcode/plugins/digikey_barcode.py b/InvenTree/barcodes/plugins/digikey_barcode.py similarity index 85% rename from InvenTree/barcode/plugins/digikey_barcode.py rename to InvenTree/barcodes/plugins/digikey_barcode.py index 1a0825e03c..656cdfa6f4 100644 --- a/InvenTree/barcode/plugins/digikey_barcode.py +++ b/InvenTree/barcodes/plugins/digikey_barcode.py @@ -4,7 +4,7 @@ DigiKey barcode decoding """ -from barcode.barcode import BarcodePlugin +from barcodes.barcode import BarcodePlugin class DigikeyBarcodePlugin(BarcodePlugin): diff --git a/InvenTree/barcode/plugins/inventree_barcode.py b/InvenTree/barcodes/plugins/inventree_barcode.py similarity index 98% rename from InvenTree/barcode/plugins/inventree_barcode.py rename to InvenTree/barcodes/plugins/inventree_barcode.py index 93fb58cbc0..842f9029aa 100644 --- a/InvenTree/barcode/plugins/inventree_barcode.py +++ b/InvenTree/barcodes/plugins/inventree_barcode.py @@ -13,7 +13,7 @@ references model objects actually exist in the database. import json -from barcode.barcode import BarcodePlugin +from barcodes.barcode import BarcodePlugin from stock.models import StockItem, StockLocation from part.models import Part diff --git a/InvenTree/barcode/tests.py b/InvenTree/barcodes/tests.py similarity index 100% rename from InvenTree/barcode/tests.py rename to InvenTree/barcodes/tests.py diff --git a/InvenTree/report/templatetags/barcode.py b/InvenTree/report/templatetags/barcode.py index 18afdea81e..9b826d8921 100644 --- a/InvenTree/report/templatetags/barcode.py +++ b/InvenTree/report/templatetags/barcode.py @@ -10,8 +10,8 @@ from io import BytesIO from django import template -import qrcode -import barcode +import qrcode as python_qrcode +import barcode as python_barcode register = template.Library() @@ -32,7 +32,7 @@ def image_data(img, fmt='PNG'): @register.simple_tag() -def qr_code(data, **kwargs): +def qrcode(data, **kwargs): """ Return a byte-encoded QR code image @@ -54,11 +54,31 @@ def qr_code(data, **kwargs): params.update(**kwargs) - qr = qrcode.QRCode(**params) + qr = python_qrcode.QRCode(**params) qr.add_data(data, optimize=20) qr.make(fit=True) qri = qr.make_image(fill_color=fill_color, back_color=back_color) - return image_data(qri) \ No newline at end of file + return image_data(qri) + + +@register.simple_tag() +def barcode(data, barcode_class='code128', **kwargs): + """ + Render a barcode + """ + + constructor = python_barcode.get_barcode_class(barcode_class) + + data = str(data).zfill(constructor.digits) + + writer = python_barcode.writer.ImageWriter + + barcode_image = constructor(data, writer=writer()) + + image = barcode_image.render(writer_options=kwargs) + + # Render to byte-encoded PNG + return image_data(image) diff --git a/InvenTree/templates/qr_code.html b/InvenTree/templates/qr_code.html index c6c2f44b87..8964ef02be 100644 --- a/InvenTree/templates/qr_code.html +++ b/InvenTree/templates/qr_code.html @@ -4,7 +4,7 @@
{% if qr_data %}
- +
{% else %}