mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fixes for barcode decoding
This commit is contained in:
parent
a4267f76e8
commit
ccda637e3c
@ -68,7 +68,7 @@ class InvenTreeBarcodePlugin(BarcodePlugin):
|
|||||||
# Initially try casting to an integer
|
# Initially try casting to an integer
|
||||||
try:
|
try:
|
||||||
pk = int(data)
|
pk = int(data)
|
||||||
except (ValueError):
|
except (TypeError, ValueError):
|
||||||
pk = None
|
pk = None
|
||||||
|
|
||||||
if pk is None:
|
if pk is None:
|
||||||
@ -89,10 +89,21 @@ class InvenTreeBarcodePlugin(BarcodePlugin):
|
|||||||
|
|
||||||
for k in self.data.keys():
|
for k in self.data.keys():
|
||||||
if k.lower() == 'stocklocation':
|
if k.lower() == 'stocklocation':
|
||||||
|
|
||||||
|
pk = None
|
||||||
|
|
||||||
|
# First try simple integer lookup
|
||||||
try:
|
try:
|
||||||
pk = self.data[k]['id']
|
pk = int(self.data[k])
|
||||||
except (AttributeError, KeyError):
|
except (TypeError, ValueError):
|
||||||
raise ValidationError({k: "id parameter not supplied"})
|
pk = None
|
||||||
|
|
||||||
|
if pk is None:
|
||||||
|
# Lookup by 'id' field
|
||||||
|
try:
|
||||||
|
pk = self.data[k]['id']
|
||||||
|
except (AttributeError, KeyError):
|
||||||
|
raise ValidationError({k: "id parameter not supplied"})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
loc = StockLocation.objects.get(pk=pk)
|
loc = StockLocation.objects.get(pk=pk)
|
||||||
@ -106,10 +117,20 @@ class InvenTreeBarcodePlugin(BarcodePlugin):
|
|||||||
|
|
||||||
for k in self.data.keys():
|
for k in self.data.keys():
|
||||||
if k.lower() == 'part':
|
if k.lower() == 'part':
|
||||||
|
|
||||||
|
pk = None
|
||||||
|
|
||||||
|
# Try integer lookup first
|
||||||
try:
|
try:
|
||||||
pk = self.data[k]['id']
|
pk = int(self.data[k])
|
||||||
except (AttributeError, KeyError):
|
except (TypeError, ValueError):
|
||||||
raise ValidationError({k, 'id parameter not supplied'})
|
pk = None
|
||||||
|
|
||||||
|
if pk is None:
|
||||||
|
try:
|
||||||
|
pk = self.data[k]['id']
|
||||||
|
except (AttributeError, KeyError):
|
||||||
|
raise ValidationError({k, 'id parameter not supplied'})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
part = Part.objects.get(pk=pk)
|
part = Part.objects.get(pk=pk)
|
||||||
|
Loading…
Reference in New Issue
Block a user