From b387b4e1733e0bc5ade3973a7d5c00183639d745 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 3 Feb 2022 14:13:13 +1100 Subject: [PATCH 1/2] Prevent build outputs being created with zero quantity --- InvenTree/build/views.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index 1a933af835..ec2ce27966 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -95,17 +95,24 @@ class BuildOutputCreate(AjaxUpdateView): quantity = form.cleaned_data.get('output_quantity', None) serials = form.cleaned_data.get('serial_numbers', None) - if quantity: + if quantity is not None: build = self.get_object() # Check that requested output don't exceed build remaining quantity maximum_output = int(build.remaining - build.incomplete_count) + if quantity > maximum_output: form.add_error( 'output_quantity', _('Maximum output quantity is ') + str(maximum_output), ) + elif quantity <= 0: + form.add_error( + 'output_quantity', + _('Output quantity must be greater than zero'), + ) + # Check that the serial numbers are valid if serials: try: From 566fd87e86848878b8b2043520c459945a82d5df Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 3 Feb 2022 14:16:33 +1100 Subject: [PATCH 2/2] PEP style fixes --- InvenTree/build/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index ec2ce27966..21cf5dda99 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -100,7 +100,7 @@ class BuildOutputCreate(AjaxUpdateView): # Check that requested output don't exceed build remaining quantity maximum_output = int(build.remaining - build.incomplete_count) - + if quantity > maximum_output: form.add_error( 'output_quantity', @@ -112,7 +112,7 @@ class BuildOutputCreate(AjaxUpdateView): 'output_quantity', _('Output quantity must be greater than zero'), ) - + # Check that the serial numbers are valid if serials: try: