implement short QR code scanning

This commit is contained in:
wolflu05 2024-07-14 13:57:24 +02:00
parent 24bd5d0962
commit e80b00f5b6
No known key found for this signature in database
GPG Key ID: 9099EFC7C5EB963C
2 changed files with 33 additions and 1 deletions

View File

@ -46,3 +46,11 @@ def get_supported_barcode_models_map():
return {
model.barcode_model_type(): model for model in get_supported_barcode_models()
}
def get_supported_barcode_model_codes_map():
"""Return a mapping of barcode model type codes to the model class."""
return {
model.barcode_model_type_code(): model
for model in get_supported_barcode_models()
}

View File

@ -8,6 +8,8 @@ references model objects actually exist in the database.
"""
import json
import re
from typing import cast
from django.core.validators import MaxLengthValidator, MinLengthValidator
from django.utils.translation import gettext_lazy as _
@ -57,8 +59,29 @@ class InvenTreeInternalBarcodePlugin(SettingsMixin, BarcodeMixin, InvenTreePlugi
Here we are looking for a dict object which contains a reference to a particular InvenTree database object
"""
# Internal Barcodes - Short Format
# Attempt to match the barcode data against the short barcode format
prefix = cast(str, self.get_setting('SHORT_BARCODE_PREFIX'))
if type(barcode_data) is str and (
m := re.match(f'^{re.escape(prefix)}(\\w{"{2}"})(\\d+)$', barcode_data)
):
model_type_code, pk = m.groups()
supported_models_map = (
plugin.base.barcodes.helper.get_supported_barcode_model_codes_map()
)
model = supported_models_map.get(model_type_code, None)
if model is None:
return None
label = model.barcode_model_type()
pk = int(pk)
return self.format_matched_response(label, model, model.objects.get(pk=pk))
# Internal Barcodes - JSON Format
# Attempt to coerce the barcode data into a dict object
# This is the internal barcode representation that InvenTree uses
# This is the internal JSON barcode representation that InvenTree uses
barcode_dict = None
if type(barcode_data) is dict:
@ -84,6 +107,7 @@ class InvenTreeInternalBarcodePlugin(SettingsMixin, BarcodeMixin, InvenTreePlugi
except (ValueError, model.DoesNotExist):
pass
# External Barcodes (Linked barcodes)
# Create hash from raw barcode data
barcode_hash = hash_barcode(barcode_data)