mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 11:10:54 +00:00
Allow barcodes to be added to incoming items via web UI (#4574)
* Fixes for receiving a line item with a barcode - Record the raw barcode data in addition to the hash * Improvements to 'receive purchase order items' dialog * Add code for assigning barcodes to incoming order items * Unit test fixes
This commit is contained in:
@ -549,11 +549,11 @@ class PurchaseOrder(TotalPriceMixin, Order):
|
||||
notes = kwargs.get('notes', '')
|
||||
|
||||
# Extract optional barcode field
|
||||
barcode_hash = kwargs.get('barcode', None)
|
||||
barcode = kwargs.get('barcode', None)
|
||||
|
||||
# Prevent null values for barcode
|
||||
if barcode_hash is None:
|
||||
barcode_hash = ''
|
||||
if barcode is None:
|
||||
barcode = ''
|
||||
|
||||
if self.status != PurchaseOrderStatus.PLACED:
|
||||
raise ValidationError(
|
||||
@ -600,10 +600,16 @@ class PurchaseOrder(TotalPriceMixin, Order):
|
||||
status=status,
|
||||
batch=batch_code,
|
||||
serial=sn,
|
||||
purchase_price=unit_purchase_price,
|
||||
barcode_hash=barcode_hash
|
||||
purchase_price=unit_purchase_price
|
||||
)
|
||||
|
||||
# Assign the provided barcode
|
||||
if barcode:
|
||||
item.assign_barcode(
|
||||
barcode_data=barcode,
|
||||
save=False
|
||||
)
|
||||
|
||||
item.save(add_note=False)
|
||||
|
||||
tracking_info = {
|
||||
|
@ -19,7 +19,8 @@ import stock.models
|
||||
import stock.serializers
|
||||
from company.serializers import (CompanyBriefSerializer, ContactSerializer,
|
||||
SupplierPartSerializer)
|
||||
from InvenTree.helpers import extract_serial_numbers, normalize, str2bool
|
||||
from InvenTree.helpers import (extract_serial_numbers, hash_barcode, normalize,
|
||||
str2bool)
|
||||
from InvenTree.serializers import (InvenTreeAttachmentSerializer,
|
||||
InvenTreeCurrencySerializer,
|
||||
InvenTreeDecimalField,
|
||||
@ -505,8 +506,8 @@ class PurchaseOrderLineItemReceiveSerializer(serializers.Serializer):
|
||||
)
|
||||
|
||||
barcode = serializers.CharField(
|
||||
label=_('Barcode Hash'),
|
||||
help_text=_('Unique identifier field'),
|
||||
label=_('Barcode'),
|
||||
help_text=_('Scanned barcode'),
|
||||
default='',
|
||||
required=False,
|
||||
allow_null=True,
|
||||
@ -519,7 +520,9 @@ class PurchaseOrderLineItemReceiveSerializer(serializers.Serializer):
|
||||
if not barcode or barcode.strip() == '':
|
||||
return None
|
||||
|
||||
if stock.models.StockItem.objects.filter(barcode_hash=barcode).exists():
|
||||
barcode_hash = hash_barcode(barcode)
|
||||
|
||||
if stock.models.StockItem.lookup_barcode(barcode_hash) is not None:
|
||||
raise ValidationError(_('Barcode is already in use'))
|
||||
|
||||
return barcode
|
||||
|
@ -837,8 +837,7 @@ class PurchaseOrderReceiveTest(OrderTest):
|
||||
"""
|
||||
# Set stock item barcode
|
||||
item = StockItem.objects.get(pk=1)
|
||||
item.barcode_hash = 'MY-BARCODE-HASH'
|
||||
item.save()
|
||||
item.assign_barcode(barcode_data='MY-BARCODE-HASH')
|
||||
|
||||
response = self.post(
|
||||
self.url,
|
||||
@ -956,8 +955,8 @@ class PurchaseOrderReceiveTest(OrderTest):
|
||||
self.assertEqual(stock_2.last().location.pk, 2)
|
||||
|
||||
# Barcodes should have been assigned to the stock items
|
||||
self.assertTrue(StockItem.objects.filter(barcode_hash='MY-UNIQUE-BARCODE-123').exists())
|
||||
self.assertTrue(StockItem.objects.filter(barcode_hash='MY-UNIQUE-BARCODE-456').exists())
|
||||
self.assertTrue(StockItem.objects.filter(barcode_data='MY-UNIQUE-BARCODE-123').exists())
|
||||
self.assertTrue(StockItem.objects.filter(barcode_data='MY-UNIQUE-BARCODE-456').exists())
|
||||
|
||||
def test_batch_code(self):
|
||||
"""Test that we can supply a 'batch code' when receiving items."""
|
||||
|
Reference in New Issue
Block a user