mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	Support non-integer serial numbers
This commit is contained in:
		@@ -371,14 +371,10 @@ def ExtractSerialNumbers(serials, expected_quantity):
 | 
				
			|||||||
                continue
 | 
					                continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            try:
 | 
					            if group in numbers:
 | 
				
			||||||
                n = int(group)
 | 
					                errors.append(_("Duplicate serial: {g}".format(g=group)))
 | 
				
			||||||
                if n in numbers:
 | 
					            else:
 | 
				
			||||||
                    errors.append(_("Duplicate serial: {n}".format(n=n)))
 | 
					                numbers.append(group)
 | 
				
			||||||
                else:
 | 
					 | 
				
			||||||
                    numbers.append(n)
 | 
					 | 
				
			||||||
            except ValueError:
 | 
					 | 
				
			||||||
                errors.append(_("Invalid group: {g}".format(g=group)))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if len(errors) > 0:
 | 
					    if len(errors) > 0:
 | 
				
			||||||
        raise ValidationError(errors)
 | 
					        raise ValidationError(errors)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -346,8 +346,10 @@ class Part(MPTTModel):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if n is None:
 | 
					        if n is None:
 | 
				
			||||||
            return 1
 | 
					            return 1
 | 
				
			||||||
        else:
 | 
					        elif n is int:
 | 
				
			||||||
            return n + 1
 | 
					            return n + 1
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def getSerialNumberString(self, quantity):
 | 
					    def getSerialNumberString(self, quantity):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										18
									
								
								InvenTree/stock/migrations/0050_auto_20200821_1403.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								InvenTree/stock/migrations/0050_auto_20200821_1403.py
									
									
									
									
									
										Normal file
									
								
							@@ -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'),
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
@@ -355,9 +355,9 @@ class StockItem(MPTTModel):
 | 
				
			|||||||
        verbose_name=_("Customer"),
 | 
					        verbose_name=_("Customer"),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    serial = models.PositiveIntegerField(
 | 
					    serial = models.CharField(
 | 
				
			||||||
        verbose_name=_('Serial Number'),
 | 
					        verbose_name=_('Serial Number'),
 | 
				
			||||||
        blank=True, null=True,
 | 
					        max_length=100, blank=True, null=True,
 | 
				
			||||||
        help_text=_('Serial number for this item')
 | 
					        help_text=_('Serial number for this item')
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
@@ -687,9 +687,6 @@ class StockItem(MPTTModel):
 | 
				
			|||||||
        if not type(serials) in [list, tuple]:
 | 
					        if not type(serials) in [list, tuple]:
 | 
				
			||||||
            raise ValidationError({"serial_numbers": _("Serial numbers must be a list of integers")})
 | 
					            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):
 | 
					        if not quantity == len(serials):
 | 
				
			||||||
            raise ValidationError({"quantity": _("Quantity does not match serial numbers")})
 | 
					            raise ValidationError({"quantity": _("Quantity does not match serial numbers")})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -129,7 +129,7 @@ class StockItemSerializer(InvenTreeModelSerializer):
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    allocated = serializers.FloatField(source='allocation_count', required=False)
 | 
					    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)
 | 
					    required_tests = serializers.IntegerField(source='required_test_count', read_only=True, required=False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user