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 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from InvenTree.forms import HelperForm
|
from InvenTree.forms import HelperForm
|
||||||
from django import forms
|
from django import forms
|
||||||
from .models import Build, BuildItem
|
from .models import Build, BuildItem
|
||||||
@ -31,7 +33,7 @@ class EditBuildForm(HelperForm):
|
|||||||
class ConfirmBuildForm(HelperForm):
|
class ConfirmBuildForm(HelperForm):
|
||||||
""" Form for auto-allocation of stock to a build """
|
""" 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:
|
class Meta:
|
||||||
model = Build
|
model = Build
|
||||||
@ -48,9 +50,9 @@ class CompleteBuildForm(HelperForm):
|
|||||||
help_text='Location of completed parts',
|
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:
|
class Meta:
|
||||||
model = Build
|
model = Build
|
||||||
|
@ -270,25 +270,29 @@ class BuildComplete(AjaxUpdateView):
|
|||||||
|
|
||||||
sn = request.POST.get('serial_numbers', '')
|
sn = request.POST.get('serial_numbers', '')
|
||||||
|
|
||||||
try:
|
sn = str(sn).strip()
|
||||||
# Exctract a list of provided serial numbers
|
|
||||||
serials = ExtractSerialNumbers(sn, build.quantity)
|
|
||||||
|
|
||||||
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:
|
existing = []
|
||||||
if not StockItem.check_serial_number(build.part, serial):
|
|
||||||
existing.append(serial)
|
|
||||||
|
|
||||||
if len(existing) > 0:
|
for serial in serials:
|
||||||
exists = ",".join([str(x) for x in existing])
|
if not StockItem.check_serial_number(build.part, serial):
|
||||||
form.errors['serial_numbers'] = [_('The following serial numbers already exist: ({sn})'.format(sn=exists))]
|
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
|
valid = False
|
||||||
|
|
||||||
except ValidationError as e:
|
|
||||||
form.errors['serial_numbers'] = e.messages
|
|
||||||
valid = False
|
|
||||||
|
|
||||||
if valid:
|
if valid:
|
||||||
build.completeBuild(location, serials, request.user)
|
build.completeBuild(location, serials, request.user)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user