Coverage for src/backend/InvenTree/plugin/builtin/suppliers/mouser.py: 68%
17 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
1"""The MouserBarcodePlugin is meant to integrate the Mouser API into InvenTree.
3This plugin currently only match Mouser barcodes to supplier parts.
4"""
6from django.utils.translation import gettext_lazy as _
8from plugin import InvenTreePlugin
9from plugin.mixins import SettingsMixin, SupplierBarcodeMixin
12class MouserPlugin(SupplierBarcodeMixin, SettingsMixin, InvenTreePlugin):
13 """Plugin to integrate the Mouser API into InvenTree."""
15 NAME = 'MouserBarcodePlugin'
16 SLUG = 'mouserplugin'
17 TITLE = _('Supplier Integration - Mouser')
18 DESCRIPTION = _('Provides support for scanning Mouser barcodes')
19 VERSION = '1.0.1'
20 AUTHOR = _('InvenTree contributors')
22 DEFAULT_SUPPLIER_NAME = 'Mouser'
23 SETTINGS = {
24 'SUPPLIER_ID': {
25 'name': _('Supplier'),
26 'description': _("The Supplier which acts as 'Mouser'"),
27 'model': 'company.company',
28 'model_filters': {'is_supplier': True},
29 }
30 }
32 def extract_barcode_fields(self, barcode_data: str) -> dict[str, str]:
33 """Get supplier_part and barcode_fields from Mouser DataMatrix-Code."""
34 barcode_fields = self.parse_ecia_barcode2d(barcode_data)
36 # Mouser uses the custom order number ('K') field of the 2D barcode for both,
37 # the order number and the customer order number
38 if order_number := barcode_fields.get(self.CUSTOMER_ORDER_NUMBER):
39 barcode_fields.setdefault(self.SUPPLIER_ORDER_NUMBER, order_number)
41 return barcode_fields