From 86b2b9cdb1ba48825e42bbbf3634cfdcbdd56bd9 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 29 Aug 2019 08:05:45 +1000 Subject: [PATCH] Allow unserialized build --- InvenTree/build/forms.py | 8 +++++--- InvenTree/build/views.py | 32 ++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/InvenTree/build/forms.py b/InvenTree/build/forms.py index 101903e1e8..54f651eade 100644 --- a/InvenTree/build/forms.py +++ b/InvenTree/build/forms.py @@ -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 diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index 7a1dceaf23..4fa6be696a 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -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)