Merge branch 'inventree:master' into matmair/issue2694

This commit is contained in:
Matthias Mair 2022-03-06 19:54:14 +01:00 committed by GitHub
commit 56142b9303
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -350,7 +350,7 @@ class StockItem(MPTTModel):
@property
def serialized(self):
""" Return True if this StockItem is serialized """
return self.serial is not None and self.quantity == 1
return self.serial is not None and len(str(self.serial).strip()) > 0 and self.quantity == 1
def validate_unique(self, exclude=None):
"""

View File

@ -346,6 +346,40 @@ class StockTest(TestCase):
with self.assertRaises(StockItem.DoesNotExist):
w2 = StockItem.objects.get(pk=101)
def test_serials(self):
"""
Tests for stock serialization
"""
p = Part.objects.create(
name='trackable part',
description='trackable part',
trackable=True,
)
item = StockItem.objects.create(
part=p,
quantity=1,
)
self.assertFalse(item.serialized)
item.serial = None
item.save()
self.assertFalse(item.serialized)
item.serial = ' '
item.save()
self.assertFalse(item.serialized)
item.serial = ''
item.save()
self.assertFalse(item.serialized)
item.serial = '1'
item.save()
self.assertTrue(item.serialized)
def test_serialize_stock_invalid(self):
"""
Test manual serialization of parts.