diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 948726d3ce..7595c550b0 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -604,6 +604,29 @@ class StockItemCreate(AjaxCreateView): form.errors['serial_numbers'] = [_('The following serial numbers already exist: ({sn})'.format(sn=exists))] valid = False + # At this point we have a list of serial numbers which we know are valid, + # and do not currently exist + form.clean() + + data = form.cleaned_data + + for serial in serials: + # Create a new stock item for each serial number + item = StockItem( + part=part, + quantity=1, + serial=serial, + supplier_part=data.get('supplier_part'), + location=data.get('location'), + batch=data.get('batch'), + delete_on_deplete=False, + status=data.get('status'), + notes=data.get('notes'), + URL=data.get('URL'), + ) + + item.save() + except ValidationError as e: form.errors['serial_numbers'] = e.messages valid = False @@ -615,8 +638,6 @@ class StockItemCreate(AjaxCreateView): form._post_clean() form.save() - print("valid:", valid) - data = { 'form_valid': valid, }