mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Allow unserialized build
This commit is contained in:
parent
937bcd41d6
commit
86b2b9cdb1
@ -5,6 +5,8 @@ Django Forms for interacting with Build objects
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from InvenTree.forms import HelperForm
|
||||
from django import forms
|
||||
from .models import Build, BuildItem
|
||||
@ -31,7 +33,7 @@ class EditBuildForm(HelperForm):
|
||||
class ConfirmBuildForm(HelperForm):
|
||||
""" Form for auto-allocation of stock to a build """
|
||||
|
||||
confirm = forms.BooleanField(required=False, help_text='Confirm')
|
||||
confirm = forms.BooleanField(required=False, help_text=_('Confirm'))
|
||||
|
||||
class Meta:
|
||||
model = Build
|
||||
@ -48,9 +50,9 @@ class CompleteBuildForm(HelperForm):
|
||||
help_text='Location of completed parts',
|
||||
)
|
||||
|
||||
serial_numbers = forms.CharField(label='Serial numbers', help_text='Enter unique serial numbers')
|
||||
serial_numbers = forms.CharField(label='Serial numbers', required=False, help_text=_('Enter unique serial numbers (or leave blank)'))
|
||||
|
||||
confirm = forms.BooleanField(required=False, help_text='Confirm build submission')
|
||||
confirm = forms.BooleanField(required=False, help_text=_('Confirm build completion'))
|
||||
|
||||
class Meta:
|
||||
model = Build
|
||||
|
@ -270,25 +270,29 @@ class BuildComplete(AjaxUpdateView):
|
||||
|
||||
sn = request.POST.get('serial_numbers', '')
|
||||
|
||||
try:
|
||||
# Exctract a list of provided serial numbers
|
||||
serials = ExtractSerialNumbers(sn, build.quantity)
|
||||
sn = str(sn).strip()
|
||||
|
||||
existing = []
|
||||
# If the user has specified serial numbers, check they are valid
|
||||
if len(sn) > 0:
|
||||
try:
|
||||
# Exctract a list of provided serial numbers
|
||||
serials = ExtractSerialNumbers(sn, build.quantity)
|
||||
|
||||
for serial in serials:
|
||||
if not StockItem.check_serial_number(build.part, serial):
|
||||
existing.append(serial)
|
||||
existing = []
|
||||
|
||||
if len(existing) > 0:
|
||||
exists = ",".join([str(x) for x in existing])
|
||||
form.errors['serial_numbers'] = [_('The following serial numbers already exist: ({sn})'.format(sn=exists))]
|
||||
for serial in serials:
|
||||
if not StockItem.check_serial_number(build.part, serial):
|
||||
existing.append(serial)
|
||||
|
||||
if len(existing) > 0:
|
||||
exists = ",".join([str(x) for x in existing])
|
||||
form.errors['serial_numbers'] = [_('The following serial numbers already exist: ({sn})'.format(sn=exists))]
|
||||
valid = False
|
||||
|
||||
except ValidationError as e:
|
||||
form.errors['serial_numbers'] = e.messages
|
||||
valid = False
|
||||
|
||||
except ValidationError as e:
|
||||
form.errors['serial_numbers'] = e.messages
|
||||
valid = False
|
||||
|
||||
if valid:
|
||||
build.completeBuild(location, serials, request.user)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user