From b387b4e1733e0bc5ade3973a7d5c00183639d745 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 3 Feb 2022 14:13:13 +1100 Subject: [PATCH] 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: