mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fix some issues with supplier barcode plugins (#5919)
* Remove unnecessary logging imports from supplier plugins * Fix MPN filtering in get_supplier_parts * Ensure digikey barcodes contain a SKU * Keep running other barcode plugins if an error occured in one of them * Fix typo (replace plugin with current_plugin) * Fix class name
This commit is contained in:
parent
dedf50da62
commit
cf3d96a265
@ -1,5 +1,6 @@
|
||||
"""API endpoints for barcode plugins."""
|
||||
|
||||
import logging
|
||||
|
||||
from django.urls import path, re_path
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@ -17,6 +18,8 @@ from plugin.builtin.barcodes.inventree_barcode import \
|
||||
from stock.models import StockLocation
|
||||
from users.models import RuleSet
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
class BarcodeScan(APIView):
|
||||
"""Endpoint for handling generic barcode scan requests.
|
||||
@ -68,7 +71,16 @@ class BarcodeScan(APIView):
|
||||
|
||||
result = current_plugin.scan(barcode_data)
|
||||
|
||||
if result is not None:
|
||||
if result is None:
|
||||
continue
|
||||
|
||||
if "error" in result:
|
||||
logger.info("%s.scan(...) returned an error: %s",
|
||||
current_plugin.__class__.__name__, result["error"])
|
||||
if not response:
|
||||
plugin = current_plugin
|
||||
response = result
|
||||
else:
|
||||
plugin = current_plugin
|
||||
response = result
|
||||
break
|
||||
@ -300,7 +312,16 @@ class BarcodePOReceive(APIView):
|
||||
location=location,
|
||||
)
|
||||
|
||||
if result is not None:
|
||||
if result is None:
|
||||
continue
|
||||
|
||||
if "error" in result:
|
||||
logger.info("%s.scan_receive_item(...) returned an error: %s",
|
||||
current_plugin.__class__.__name__, result["error"])
|
||||
if not response:
|
||||
plugin = current_plugin
|
||||
response = result
|
||||
else:
|
||||
plugin = current_plugin
|
||||
response = result
|
||||
break
|
||||
|
@ -130,7 +130,7 @@ class BarcodeMixin:
|
||||
return supplier_parts
|
||||
|
||||
if mpn:
|
||||
supplier_parts = SupplierPart.objects.filter(manufacturer_part__MPN__iexact=mpn)
|
||||
supplier_parts = supplier_parts.filter(manufacturer_part__MPN__iexact=mpn)
|
||||
if len(supplier_parts) == 1:
|
||||
return supplier_parts
|
||||
|
||||
|
@ -3,16 +3,12 @@
|
||||
This plugin can currently only match DigiKey barcodes to supplier parts.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from plugin import InvenTreePlugin
|
||||
from plugin.base.barcodes.mixins import SupplierBarcodeData
|
||||
from plugin.mixins import SettingsMixin, SupplierBarcodeMixin
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
class DigiKeyPlugin(SupplierBarcodeMixin, SettingsMixin, InvenTreePlugin):
|
||||
"""Plugin to integrate the DigiKey API into Inventree."""
|
||||
@ -41,6 +37,10 @@ class DigiKeyPlugin(SupplierBarcodeMixin, SettingsMixin, InvenTreePlugin):
|
||||
if not (barcode_fields := self.parse_ecia_barcode2d(barcode_data)):
|
||||
return None
|
||||
|
||||
# digikey barcodes should always contain a SKU
|
||||
if "supplier_part_number" not in barcode_fields:
|
||||
return None
|
||||
|
||||
return SupplierBarcodeData(
|
||||
SKU=barcode_fields.get("supplier_part_number"),
|
||||
MPN=barcode_fields.get("manufacturer_part_number"),
|
||||
|
@ -3,7 +3,6 @@
|
||||
This plugin can currently only match LCSC barcodes to supplier parts.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import re
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@ -12,8 +11,6 @@ from plugin import InvenTreePlugin
|
||||
from plugin.base.barcodes.mixins import SupplierBarcodeData
|
||||
from plugin.mixins import SettingsMixin, SupplierBarcodeMixin
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
class LCSCPlugin(SupplierBarcodeMixin, SettingsMixin, InvenTreePlugin):
|
||||
"""Plugin to integrate the LCSC API into Inventree."""
|
||||
|
@ -3,16 +3,12 @@
|
||||
This plugin currently only match Mouser barcodes to supplier parts.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from plugin import InvenTreePlugin
|
||||
from plugin.base.barcodes.mixins import SupplierBarcodeData
|
||||
from plugin.mixins import SettingsMixin, SupplierBarcodeMixin
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
class MouserPlugin(SupplierBarcodeMixin, SettingsMixin, InvenTreePlugin):
|
||||
"""Plugin to integrate the Mouser API into Inventree."""
|
||||
|
@ -3,7 +3,6 @@
|
||||
This plugin can currently only match TME barcodes to supplier parts.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import re
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@ -12,8 +11,6 @@ from plugin import InvenTreePlugin
|
||||
from plugin.base.barcodes.mixins import SupplierBarcodeData
|
||||
from plugin.mixins import SettingsMixin, SupplierBarcodeMixin
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
class TMEPlugin(SupplierBarcodeMixin, SettingsMixin, InvenTreePlugin):
|
||||
"""Plugin to integrate the TME API into Inventree."""
|
||||
|
Loading…
Reference in New Issue
Block a user