mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
catch errors if model with pk is not found for scanning and generating
This commit is contained in:
parent
3999ae60db
commit
650787af55
@ -162,7 +162,10 @@ class BarcodeGenerate(CreateAPIView):
|
||||
if model_cls is None:
|
||||
raise ValidationError({'error': _('Model is not supported')})
|
||||
|
||||
try:
|
||||
model_instance = model_cls.objects.get(pk=pk)
|
||||
except model_cls.DoesNotExist:
|
||||
raise ValidationError({'error': _('Model instance not found')})
|
||||
|
||||
barcode_data = plugin.base.barcodes.helper.generate_barcode(model_instance)
|
||||
|
||||
|
@ -76,8 +76,12 @@ class InvenTreeInternalBarcodePlugin(SettingsMixin, BarcodeMixin, InvenTreePlugi
|
||||
return None
|
||||
|
||||
label = model.barcode_model_type()
|
||||
pk = int(pk)
|
||||
return self.format_matched_response(label, model, model.objects.get(pk=pk))
|
||||
|
||||
try:
|
||||
instance = model.objects.get(pk=int(pk))
|
||||
return self.format_matched_response(label, model, instance)
|
||||
except (ValueError, model.DoesNotExist):
|
||||
pass
|
||||
|
||||
# Internal Barcodes - JSON Format
|
||||
# Attempt to coerce the barcode data into a dict object
|
||||
|
Loading…
Reference in New Issue
Block a user