better group handeling

This commit is contained in:
Matthias 2021-12-29 16:13:44 +01:00
parent 410c190ddf
commit ed09d5015a
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -11,6 +11,7 @@ from PIL import Image
from decimal import Decimal, InvalidOperation from decimal import Decimal, InvalidOperation
from wsgiref.util import FileWrapper from wsgiref.util import FileWrapper
from django.db.models.expressions import RawSQL
from django.http import StreamingHttpResponse from django.http import StreamingHttpResponse
from django.core.exceptions import ValidationError, FieldError from django.core.exceptions import ValidationError, FieldError
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -500,12 +501,20 @@ def extract_serial_numbers(serials, expected_quantity, next_number: int):
errors.append(_("Invalid group: {g}").format(g=group)) errors.append(_("Invalid group: {g}").format(g=group))
continue continue
# Group is a number # Group should be a number
elif group:
# try conversion
try:
number = int(group)
except:
# seem like it is not a number
raise ValidationError(_(f"Invalid group {group}"))
number_add(number)
# No valid input group detected
else: else:
if group in numbers: raise ValidationError(_(f"Invalid/no group {group}"))
errors.append(_("Duplicate serial: {g}".format(g=group)))
else:
numbers.append(int(group))
if len(errors) > 0: if len(errors) > 0:
raise ValidationError(errors) raise ValidationError(errors)