From f7ed48809cb0d73f21b488988f067dcecdc33099 Mon Sep 17 00:00:00 2001 From: Ben Charlton Date: Fri, 21 Aug 2020 17:36:49 +0100 Subject: [PATCH] Support non-integer serial numbers --- InvenTree/InvenTree/helpers.py | 12 ++++-------- InvenTree/part/models.py | 4 +++- .../migrations/0050_auto_20200821_1403.py | 18 ++++++++++++++++++ InvenTree/stock/models.py | 7 ++----- InvenTree/stock/serializers.py | 2 +- 5 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 InvenTree/stock/migrations/0050_auto_20200821_1403.py diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index 28cebbcd3d..4ec84c7912 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -371,14 +371,10 @@ def ExtractSerialNumbers(serials, expected_quantity): continue else: - try: - n = int(group) - if n in numbers: - errors.append(_("Duplicate serial: {n}".format(n=n))) - else: - numbers.append(n) - except ValueError: - errors.append(_("Invalid group: {g}".format(g=group))) + if group in numbers: + errors.append(_("Duplicate serial: {g}".format(g=group))) + else: + numbers.append(group) if len(errors) > 0: raise ValidationError(errors) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index dd126d5730..6d42b08101 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -346,8 +346,10 @@ class Part(MPTTModel): if n is None: return 1 - else: + elif n is int: return n + 1 + else: + return None def getSerialNumberString(self, quantity): """ diff --git a/InvenTree/stock/migrations/0050_auto_20200821_1403.py b/InvenTree/stock/migrations/0050_auto_20200821_1403.py new file mode 100644 index 0000000000..fa02c0d0f7 --- /dev/null +++ b/InvenTree/stock/migrations/0050_auto_20200821_1403.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2020-08-21 14:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0049_auto_20200820_0454'), + ] + + operations = [ + migrations.AlterField( + model_name='stockitem', + name='serial', + field=models.CharField(blank=True, help_text='Serial number for this item', max_length=100, null=True, verbose_name='Serial Number'), + ), + ] diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 49c185220f..c10295ee6a 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -355,9 +355,9 @@ class StockItem(MPTTModel): verbose_name=_("Customer"), ) - serial = models.PositiveIntegerField( + serial = models.CharField( verbose_name=_('Serial Number'), - blank=True, null=True, + max_length=100, blank=True, null=True, help_text=_('Serial number for this item') ) @@ -687,9 +687,6 @@ class StockItem(MPTTModel): if not type(serials) in [list, tuple]: raise ValidationError({"serial_numbers": _("Serial numbers must be a list of integers")}) - if any([type(i) is not int for i in serials]): - raise ValidationError({"serial_numbers": _("Serial numbers must be a list of integers")}) - if not quantity == len(serials): raise ValidationError({"quantity": _("Quantity does not match serial numbers")}) diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py index bed3f8f7c1..2967538e88 100644 --- a/InvenTree/stock/serializers.py +++ b/InvenTree/stock/serializers.py @@ -129,7 +129,7 @@ class StockItemSerializer(InvenTreeModelSerializer): allocated = serializers.FloatField(source='allocation_count', required=False) - serial = serializers.IntegerField(required=False) + serial = serializers.CharField(required=False) required_tests = serializers.IntegerField(source='required_test_count', read_only=True, required=False)