mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fix supplier barcode order numbers (#6158)
* Add tme barcode CPO field * Fix LCSC order number field * Fix mouser order number field * Fix get_purchase_orders logic * Refine get_purchase_orders logic * Slightly refactor get_purchase_orders logic
This commit is contained in:
parent
d1cc81fc9f
commit
36bb3c5645
@ -6,7 +6,7 @@ import logging
|
||||
from decimal import Decimal, InvalidOperation
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models import F
|
||||
from django.db.models import F, Q
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from company.models import Company, SupplierPart
|
||||
@ -347,12 +347,17 @@ class SupplierBarcodeMixin(BarcodeMixin):
|
||||
if supplier:
|
||||
orders = orders.filter(supplier=supplier)
|
||||
|
||||
if customer_order_number:
|
||||
orders = orders.filter(reference__iexact=customer_order_number)
|
||||
elif supplier_order_number:
|
||||
orders = orders.filter(supplier_reference__iexact=supplier_order_number)
|
||||
# this works because reference and supplier_reference are not nullable, so if
|
||||
# customer_order_number or supplier_order_number is None, the query won't return anything
|
||||
reference_filter = Q(reference__iexact=customer_order_number)
|
||||
supplier_reference_filter = Q(supplier_reference__iexact=supplier_order_number)
|
||||
|
||||
return orders
|
||||
orders_union = orders.filter(reference_filter | supplier_reference_filter)
|
||||
if orders_union.count() == 1:
|
||||
return orders_union
|
||||
else:
|
||||
orders_intersection = orders.filter(reference_filter & supplier_reference_filter)
|
||||
return orders_intersection if orders_intersection else orders_union
|
||||
|
||||
@staticmethod
|
||||
def get_supplier_parts(sku: str = None, supplier: Company = None, mpn: str = None):
|
||||
|
@ -36,7 +36,7 @@ class LCSCPlugin(SupplierBarcodeMixin, SettingsMixin, InvenTreePlugin):
|
||||
"pm": SupplierBarcodeMixin.MANUFACTURER_PART_NUMBER,
|
||||
"pc": SupplierBarcodeMixin.SUPPLIER_PART_NUMBER,
|
||||
"qty": SupplierBarcodeMixin.QUANTITY,
|
||||
"on": SupplierBarcodeMixin.CUSTOMER_ORDER_NUMBER,
|
||||
"on": SupplierBarcodeMixin.SUPPLIER_ORDER_NUMBER,
|
||||
}
|
||||
|
||||
def extract_barcode_fields(self, barcode_data: str) -> dict[str, str]:
|
||||
|
@ -30,4 +30,11 @@ class MouserPlugin(SupplierBarcodeMixin, SettingsMixin, InvenTreePlugin):
|
||||
def extract_barcode_fields(self, barcode_data: str) -> dict[str, str]:
|
||||
"""Get supplier_part and barcode_fields from Mouser DataMatrix-Code."""
|
||||
|
||||
return self.parse_ecia_barcode2d(barcode_data)
|
||||
barcode_fields = self.parse_ecia_barcode2d(barcode_data)
|
||||
|
||||
# Mouser uses the custom order number ('K') field of the 2D barcode for both,
|
||||
# the order number and the customer order number
|
||||
if order_number := barcode_fields.get(self.CUSTOMER_ORDER_NUMBER):
|
||||
barcode_fields.setdefault(self.SUPPLIER_ORDER_NUMBER, order_number)
|
||||
|
||||
return barcode_fields
|
||||
|
@ -35,7 +35,8 @@ class TMEPlugin(SupplierBarcodeMixin, SettingsMixin, InvenTreePlugin):
|
||||
# Custom field mapping
|
||||
TME_QRCODE_FIELDS = {
|
||||
"PN": SupplierBarcodeMixin.SUPPLIER_PART_NUMBER,
|
||||
"PO": SupplierBarcodeMixin.CUSTOMER_ORDER_NUMBER,
|
||||
"CPO": SupplierBarcodeMixin.CUSTOMER_ORDER_NUMBER,
|
||||
"PO": SupplierBarcodeMixin.SUPPLIER_ORDER_NUMBER,
|
||||
"MPN": SupplierBarcodeMixin.MANUFACTURER_PART_NUMBER,
|
||||
"QTY": SupplierBarcodeMixin.QUANTITY,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user