From 852da6d696feac6d3241aaf8741280fbd4cc1194 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 4 Oct 2020 23:48:15 +1100 Subject: [PATCH] Fix form validation --- InvenTree/stock/forms.py | 8 ++++---- InvenTree/templates/js/stock.html | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index 85a520fed5..2502fc1869 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -282,7 +282,7 @@ class InstallStockForm(HelperForm): part = forms.ModelChoiceField( queryset=Part.objects.all(), - widget=forms.HiddenInput + widget=forms.HiddenInput() ) stock_item = forms.ModelChoiceField( @@ -321,10 +321,10 @@ class InstallStockForm(HelperForm): print("Data:", data) - stock_item = data['stock_item'] - quantity = data['quantity_to_install'] + stock_item = data.get('stock_item', None) + quantity = data.get('quantity_to_install', None) - if quantity > stock_item.quantity: + if stock_item and quantity and quantity > stock_item.quantity: raise ValidationError({'quantity_to_install': _('Must not exceed available quantity')}) return data diff --git a/InvenTree/templates/js/stock.html b/InvenTree/templates/js/stock.html index b3ea0f2baa..0ebedbfb6e 100644 --- a/InvenTree/templates/js/stock.html +++ b/InvenTree/templates/js/stock.html @@ -1078,8 +1078,6 @@ function loadInstalledInTable(table, options) { if (!match) { // The stock item did *not* match any items in the BOM! // Add a new row to the table... - - console.log("Found an unmatched part! " + item.pk + " -> " + item.part); // Contruct a new "row" to add to the table var new_row = {